Skip to content

Commit

Permalink
Merge pull request #7044 from TheZlodziej/master
Browse files Browse the repository at this point in the history
fix: InputNumber unexpected behavior when using allow-empty attribute…
  • Loading branch information
tugcekucukoglu authored Jan 8, 2025
2 parents 025d79d + 894779b commit 94dd70d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/primevue/src/inputnumber/InputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ export default {
let newValueStr;
if (sign.isMinusSign) {
if (selectionStart === 0) {
const value = this.parseValue(inputValue);
if (selectionStart === 0 || value === 0) {
newValueStr = inputValue;
if (minusCharIndex === -1 || selectionEnd !== 0) {
Expand Down Expand Up @@ -782,8 +784,16 @@ export default {
if (valueStr != null) {
newValue = this.parseValue(valueStr);
newValue = !newValue && !this.allowEmpty ? 0 : newValue;
this.updateInput(newValue, insertedValueStr, operation, 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);
}
this.handleOnInput(event, currentValue, newValue);
}
Expand Down Expand Up @@ -864,7 +874,7 @@ 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 + 1, selectionEnd + 1);
this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd);
} 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 94dd70d

Please sign in to comment.