Skip to content

Commit

Permalink
fix: prevent caret position from jumping to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
dm4t2 committed Oct 30, 2021
1 parent 549fa48 commit 73904c2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/numberInput.ts
Expand Up @@ -206,6 +206,10 @@ export class NumberInput {
return newValueLength - caretPositionFromLeft - 1
}

if (newValueLength < caretPositionFromLeft) {
return selectionStart
}

if (decimalSymbol !== undefined && value.indexOf(decimalSymbol) !== -1) {
const decimalSymbolPosition = value.indexOf(decimalSymbol) + 1
if (Math.abs(newValueLength - value.length) > 1 && selectionStart <= decimalSymbolPosition) {
Expand Down

0 comments on commit 73904c2

Please sign in to comment.