Skip to content

Commit

Permalink
Merge pull request #6845 from Abassion/master
Browse files Browse the repository at this point in the history
Fix #6837 - Updated onInputKeyDown() on InputNumber so that it works as expected
  • Loading branch information
tugcekucukoglu authored Nov 25, 2024
2 parents 96ad315 + 146af0f commit a2348d9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/primevue/src/inputnumber/InputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Check failure on line 407 in packages/primevue/src/inputnumber/InputNumber.vue

View workflow job for this annotation

GitHub Actions / build (18)

Expected blank line before this statement

Check failure on line 407 in packages/primevue/src/inputnumber/InputNumber.vue

View workflow job for this annotation

GitHub Actions / build (20)

Expected blank line before this statement
} 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);

Check failure on line 417 in packages/primevue/src/inputnumber/InputNumber.vue

View workflow job for this annotation

GitHub Actions / build (18)

Expected blank line before this statement

Check failure on line 417 in packages/primevue/src/inputnumber/InputNumber.vue

View workflow job for this annotation

GitHub Actions / build (20)

Expected blank line before this statement
} else if (!this.isNumeralChar(inputValue.charAt(selectionStart))) {
event.preventDefault();
}
Expand Down

0 comments on commit a2348d9

Please sign in to comment.