Skip to content

[@mantine/core] PinInput: Use effective input mode for numeric key filtering - #9555

Open
rishabhx29 wants to merge 1 commit into
mantinedev:masterfrom
rishabhx29:fix/pininput-effective-input-mode
Open

rishabhx29 wants to merge 1 commit into
mantinedev:masterfrom
rishabhx29:fix/pininput-effective-input-mode

Conversation

@rishabhx29

Copy link
Copy Markdown
Contributor

Problem

PinInput derives an effective input mode for rendering:

inputMode={inputMode || (type === 'number' ? 'numeric' : 'text')}

but the keydown filter checks the raw prop:

if (inputMode === 'numeric') { ... }

With type="number" and no explicit inputMode, the rendered input is numeric while the key filter is skipped, so non-numeric keys are not prevented.

Reproduction

const { container } = render(<PinInput length={4} type="number" />);
const input = container.querySelectorAll('input')[0];
expect(fireEvent.keyDown(input, { key: 'a' })).toBe(false);

On unfixed master the event is not prevented (Received: true).

Solution

Compute effectiveInputMode once and use it both for the inputMode attribute and the keydown filter.

Tests

Added a regression test asserting inputmode="numeric", that a letter key is prevented and that a digit key is not. Full PinInput suite: 99 tests passed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant