Skip to content

Commit

Permalink
Fixed #1585 - InputNumber feature - allow negative values
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Sep 20, 2020
1 parent 1723aad commit d1b3570
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,10 @@ export class InputNumber extends Component {
}
}

allowMinusSign() {
return this.props.min === null || this.props.min < 0;
}

isMinusSign(char) {
if (this._minusSign.test(char)) {
this._minusSign.lastIndex = 0;
Expand All @@ -495,6 +499,12 @@ export class InputNumber extends Component {
}

insert(event, text, sign = { isDecimalSign: false, isMinusSign: false }) {
const minusCharIndexOnText = text.search(this._minusSign);
this._minusSign.lastIndex = 0;
if (!this.allowMinusSign() && minusCharIndexOnText !== -1) {
return;
}

const selectionStart = this.inputEl.selectionStart;
const selectionEnd = this.inputEl.selectionEnd;
let inputValue = this.inputEl.value.trim();
Expand Down

0 comments on commit d1b3570

Please sign in to comment.