From 146af0f69e9cd359d31dc35ef92778213fb5bd95 Mon Sep 17 00:00:00 2001 From: Abdelillah Aissani Date: Sat, 23 Nov 2024 15:06:06 +0100 Subject: [PATCH] Updated onInputKeyDown() on InputNumber.vue. so that it works as expected when the input value is selected. --- packages/primevue/src/inputnumber/InputNumber.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/primevue/src/inputnumber/InputNumber.vue b/packages/primevue/src/inputnumber/InputNumber.vue index 01e0a4e4ac..41d1936b6b 100755 --- a/packages/primevue/src/inputnumber/InputNumber.vue +++ b/packages/primevue/src/inputnumber/InputNumber.vue @@ -385,6 +385,7 @@ export default { let selectionStart = event.target.selectionStart; let selectionEnd = event.target.selectionEnd; + let selectionRange = selectionEnd - selectionStart; let inputValue = event.target.value; let newValueStr = null; const code = event.code || event.key; @@ -401,14 +402,20 @@ export default { break; case 'ArrowLeft': - if (!this.isNumeralChar(inputValue.charAt(selectionStart - 1))) { + if (selectionRange > 1) { + const cursorPosition = this.isNumeralChar(inputValue.charAt(selectionStart)) ? selectionStart + 1 : selectionStart + 2; + this.$refs.input.$el.setSelectionRange(cursorPosition, cursorPosition); + } else if (!this.isNumeralChar(inputValue.charAt(selectionStart - 1))) { event.preventDefault(); } break; case 'ArrowRight': - if (!this.isNumeralChar(inputValue.charAt(selectionStart))) { + if (selectionRange > 1) { + const cursorPosition = selectionEnd - 1; + this.$refs.input.$el.setSelectionRange(cursorPosition, cursorPosition); + } else if (!this.isNumeralChar(inputValue.charAt(selectionStart))) { event.preventDefault(); }