Skip to content

Commit

Permalink
Account for removed commas when deleting in currency mask
Browse files Browse the repository at this point in the history
  • Loading branch information
kangaree committed Dec 6, 2024
1 parent efd7fca commit 70a2066
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion playbook/app/pb_kits/playbook/pb_text_input/_text_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>

// Keep cursor position
if (!isAtEnd) {
// Account for added characters (e.g., commas added in currency)
// Account for extra characters (e.g., commas added/removed in currency)
if (formattedValue.length - inputValue.length === 1) {
cursorPosition = cursorPosition + 1
} else if (mask === "currency" && formattedValue.length - inputValue.length === -1) {
cursorPosition = cursorPosition - 1
}
e.target.selectionStart = e.target.selectionEnd = cursorPosition
}
Expand Down

0 comments on commit 70a2066

Please sign in to comment.