Skip to content

Commit

Permalink
Merge pull request #714 from chiragg928/feat(QtySelector)
Browse files Browse the repository at this point in the history
feat(QtySelector): add incrementBtnProps and decrementBtnProps props
  • Loading branch information
kksarma authored Mar 18, 2021
2 parents 3ef4d66 + f0c9a46 commit 218e318
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 9 additions & 1 deletion catalog/pages/inputs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,14 @@ rows:
Type: string
Default: Decrease Quantity
Notes: Aria label of the Decrement button for accessibility requirement
- Prop: incrementBtnProps
Type: object
Default: "{ }"
Notes: Extra props passed only to the increment button.
- Prop: decrementBtnProps
Type: object
Default: "{ }"
Notes: Extra props passed only to the decrement button.
```

It also accepts any event handlers. e.g. `onBlur`, `onFocus` etc. as well as styles object.
Expand All @@ -1290,7 +1298,7 @@ span: 6
---
<div style={{ display: 'flex' }}>
<div style={{ width: '30%' }}>
<QtySelector value={50} />
<QtySelector value={50} decrementBtnProps={{className:"classOnDecrementBtn"}} incrementBtnProps={{className:"classOnIncrementBtn"}} />
</div>
<div style={{ width: '30%' }}>
<QtySelector value={2} min={2} max={4}/>
Expand Down
16 changes: 13 additions & 3 deletions src/components/Input/QtySelector/QtySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class QtySelector extends Component {
checkValue: PropTypes.func,
handleValueUpdate: PropTypes.func,
incrementBtnLabel: PropTypes.string,
decrementBtnLabel: PropTypes.string
decrementBtnLabel: PropTypes.string,
/* eslint-disable react/forbid-prop-types */
incrementBtnProps: PropTypes.object,
decrementBtnProps: PropTypes.object
/* eslint-enable react/forbid-prop-types */
};

static defaultProps = {
Expand All @@ -49,7 +53,9 @@ class QtySelector extends Component {
checkValue: () => true,
handleValueUpdate: () => {},
incrementBtnLabel: "Increase Quantity",
decrementBtnLabel: "Decrease Quantity"
decrementBtnLabel: "Decrease Quantity",
incrementBtnProps: {},
decrementBtnProps: {}
};

state = {
Expand Down Expand Up @@ -174,13 +180,16 @@ class QtySelector extends Component {
min,
max,
decrementBtnLabel,
incrementBtnLabel
incrementBtnLabel,
decrementBtnProps,
incrementBtnProps
} = this.props;
const { value } = this.state;

return (
<Container>
<Button
{...decrementBtnProps}
onClick={this.decrement}
disabled={disabled || min === value}
aria-label={decrementBtnLabel}
Expand All @@ -195,6 +204,7 @@ class QtySelector extends Component {
{this.renderInput()}
</InputFieldContainer>
<Button
{...incrementBtnProps}
onClick={this.increment}
disabled={disabled || max === value}
aria-label={incrementBtnLabel}
Expand Down

0 comments on commit 218e318

Please sign in to comment.