From 600e36aab146c61f51b6d40a4ffe91ecffbb6872 Mon Sep 17 00:00:00 2001 From: minekuba Date: Sat, 4 Jan 2025 01:38:41 +0100 Subject: [PATCH 1/2] fix: InputNumber unexpected behavior when using allow-empty attribute combined with min attribute. --- packages/primevue/src/inputnumber/InputNumber.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/primevue/src/inputnumber/InputNumber.vue b/packages/primevue/src/inputnumber/InputNumber.vue index 3e5f31215..aad82e928 100755 --- a/packages/primevue/src/inputnumber/InputNumber.vue +++ b/packages/primevue/src/inputnumber/InputNumber.vue @@ -782,8 +782,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); } @@ -864,7 +872,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') { From 894779ba7c50202163daf9c6fb7b1e5a1e42927a Mon Sep 17 00:00:00 2001 From: minekuba Date: Sat, 4 Jan 2025 01:52:53 +0100 Subject: [PATCH 2/2] fix: InputNumber cannot enter negative values 0 when using allow-empty=false --- packages/primevue/src/inputnumber/InputNumber.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/primevue/src/inputnumber/InputNumber.vue b/packages/primevue/src/inputnumber/InputNumber.vue index aad82e928..af0026a6c 100755 --- a/packages/primevue/src/inputnumber/InputNumber.vue +++ b/packages/primevue/src/inputnumber/InputNumber.vue @@ -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) {