Skip to content

Commit

Permalink
Fixed #7045 - InputNumber weird behavior when using min value & allow…
Browse files Browse the repository at this point in the history
…-empty=false together
  • Loading branch information
tugcekucukoglu committed Jan 8, 2025
1 parent 94dd70d commit 337ef44
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions packages/primevue/src/inputnumber/InputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,12 @@ export default {
let newValueStr;
if (sign.isMinusSign) {
const value = this.parseValue(inputValue);
const isNewMinusSign = minusCharIndex === -1;
if (selectionStart === 0 || value === 0) {
if (selectionStart === 0 || selectionStart === currencyCharIndex + 1) {
newValueStr = inputValue;
if (minusCharIndex === -1 || selectionEnd !== 0) {
if (isNewMinusSign || selectionEnd !== 0) {
newValueStr = this.insertText(inputValue, text, 0, selectionEnd);
}
Expand Down Expand Up @@ -784,16 +784,8 @@ export default {
if (valueStr != null) {
newValue = this.parseValue(valueStr);
if (!newValue && !this.allowEmpty) {
newValue = 0;
this.updateInput(newValue, insertedValueStr, operation, valueStr);
const cursorPos = this.prefix ? this.prefix.length + 1 : 1;
this.$refs.input.$el.setSelectionRange(cursorPos, cursorPos);
} else {
this.updateInput(newValue, insertedValueStr, operation, valueStr);
}
newValue = !newValue && !this.allowEmpty ? this.min || 0 : newValue;
this.updateInput(newValue, insertedValueStr, operation, valueStr);
this.handleOnInput(event, currentValue, newValue);
}
Expand Down Expand Up @@ -874,7 +866,16 @@ export default {
this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd);
} else if (newLength === currentLength) {
if (operation === 'insert' || operation === 'delete-back-single') {
this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd);
let newSelectionEnd = selectionEnd;
if (insertedValueStr === '0') {
newSelectionEnd = selectionEnd + 1;
} else {
console.log(Number(this.isDecimalSign(value) || this.isDecimalSign(insertedValueStr)));
newSelectionEnd = newSelectionEnd + Number(this.isDecimalSign(value) || this.isDecimalSign(insertedValueStr));
}
this.$refs.input.$el.setSelectionRange(newSelectionEnd, newSelectionEnd);
} else if (operation === 'delete-single') {
this.$refs.input.$el.setSelectionRange(selectionEnd - 1, selectionEnd - 1);
} else if (operation === 'delete-range' || operation === 'spin') {
Expand Down

0 comments on commit 337ef44

Please sign in to comment.