Skip to content

Commit

Permalink
Fix #2465: InputNumber default to min on allowEmpty=false (#2472)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Dec 10, 2021
1 parent 0fe0b1a commit e4c8d58
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/components/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,13 +783,21 @@ export class InputNumber extends Component {

if (valueStr != null) {
newValue = this.parseValue(valueStr);
newValue = !newValue && !this.props.allowEmpty ? 0 : newValue;
newValue = this.evaluateEmpty(newValue);
this.updateInput(newValue, insertedValueStr, operation, valueStr);

this.handleOnChange(event, currentValue, newValue);
}
}

evaluateEmpty(newValue) {
let minimum = this.props.min || 0;
if (minimum < 0) {
minimum = 0;
}
return !newValue && !this.props.allowEmpty ? minimum : newValue;
}

handleOnChange(event, currentValue, newValue) {
if (this.props.onChange && this.isValueChanged(currentValue, newValue)) {
this.props.onChange({
Expand Down Expand Up @@ -907,7 +915,7 @@ export class InputNumber extends Component {
}

updateInputValue(newValue) {
newValue = !newValue && !this.props.allowEmpty ? 0 : newValue;
newValue = this.evaluateEmpty(newValue);

const inputEl = this.inputRef.current;
const value = inputEl.value;
Expand All @@ -920,8 +928,8 @@ export class InputNumber extends Component {
}

formattedValue(val) {
const newVal = !val && !this.props.allowEmpty ? 0 : val;
return this.formatValue(newVal);
const newValue = this.evaluateEmpty(val);
return this.formatValue(newValue);
}

concatValues(val1, val2) {
Expand Down

0 comments on commit e4c8d58

Please sign in to comment.