Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core] NumberInput: Fix (#5432) #5471

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,30 @@ describe('@mantine/core/NumberInput', () => {
await enterText('{arrowdown}');
expect(spy).toHaveBeenCalledTimes(2);
});

it('checks whether the data entered is larger than Number.MAX_SAFE_INT', async () => {
const spy = jest.fn();
render(<NumberInput value={9007199254740991} onChange={spy} />);

focusInput();
await enterText('{backspace}');
expect(spy).toHaveBeenLastCalledWith(900719925474099);
expect(spy).toHaveBeenCalledTimes(1);

await enterText('2');
expect(spy).toHaveBeenLastCalledWith('9007199254740992');
expect(spy).toHaveBeenCalledTimes(2);

await enterText('7');
expect(spy).toHaveBeenLastCalledWith('90071992547409927');
expect(spy).toHaveBeenCalledTimes(3);

await enterText('{backspace}');
await enterText('{backspace}');
await enterText('{backspace}');
await enterText('{backspace}');
await enterText('{backspace}');
expect(spy).toHaveBeenLastCalledWith(900719925474);
expect(spy).toHaveBeenCalledTimes(8);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export interface NumberInputHandlers {
}

function isValidNumber(value: number | string | undefined): value is number {
return (typeof value === 'number' || !Number.isNaN(Number(value))) && !Number.isNaN(value);
return (
(typeof value === 'number' ? value < Number.MAX_SAFE_INTEGER : !Number.isNaN(Number(value))) &&
!Number.isNaN(value)
);
}

interface GetDecrementedValueInput {
Expand Down