Skip to content

Commit 8c6bce0

Browse files
committed
🐛 Prevent insert higher amounts while disableAdd is set
1 parent 4cb689a commit 8c6bce0

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/react-chayns-amountcontrol/component/AmountControl.jsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,31 @@ export default class AmountControl extends PureComponent {
139139
};
140140

141141
changeAmount = (amount) => {
142-
const { onChange, onInput } = this.props;
142+
const {
143+
onChange,
144+
onInput,
145+
amount: oldAmount,
146+
disableAdd,
147+
disableRemove,
148+
} = this.props;
149+
150+
if (onInput) {
151+
onInput(amount);
152+
}
143153

144154
if (onChange) {
155+
if ((disableAdd && amount > oldAmount)
156+
|| (disableRemove && amount < oldAmount)) {
157+
this.setState({
158+
tempValue: oldAmount,
159+
});
160+
161+
return;
162+
}
163+
145164
onChange(amount);
146165
this.setInput(false);
147166
}
148-
149-
if (onInput) {
150-
onInput(amount);
151-
}
152167
};
153168

154169
setInput = (value) => {

0 commit comments

Comments
 (0)