Skip to content

Commit

Permalink
Add a possible solution
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Jan 9, 2024
1 parent ea2cf1e commit 95c276f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ const useCallEvent = ({ setLocalValue }) => {
const cleanedValue =
numberValue === 0 && String(num).charAt(0) !== '0' ? '' : num

if (name === 'on_change' && numberValue === 0) {
if (
name === 'on_key_down' ||
(name === 'on_change' && numberValue === 0)
) {
correctCaretPosition(event.target, maskParams, props)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1702,25 +1702,21 @@ describe('InputMasked with custom mask', () => {
})

it('should set correct cursor position when navigating using keyboard', async () => {
render(
<InputMasked
value='1'
mask={[/\d/, ' ', /\d/]}
/>
)
render(<InputMasked value="1" mask={[/\d/, ' ', /\d/]} />)

const input = document.querySelector('input')

{
expect(document.body).toHaveFocus()

await userEvent.tab()

expect(input).toHaveFocus()
expect(input).toHaveValue(`1 ​`)
expect(input).toHaveValue('1 ​')

await userEvent.keyboard('{ArrowRight}2') // Remove selection

await userEvent.keyboard('{arrowright}') // removes selection
await userEvent.keyboard('2')
expect(input).toHaveValue(`1 2`)
expect(input).toHaveValue('1 2')
}
})

Expand Down

0 comments on commit 95c276f

Please sign in to comment.