Skip to content

Commit

Permalink
[@mantine/core] NumberInput: Fix incorrect min prop handling for la…
Browse files Browse the repository at this point in the history
…rge numbers (#6985)

Previously values that only contain a minus would have been considered
valid which triggers things like min/max clamping even though it
should not.

Fixes #6969
  • Loading branch information
richardboehme authored Oct 16, 2024
1 parent f75b5ab commit 1dce6ac
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ function getDecimalPlaces(inputValue: string | number): number {
return inputValue.toString().replace('.', '').length;
}

function isValidNumber(
floatValue: number | undefined,
value: string | undefined
): floatValue is number {
if (typeof value === 'string') {
return getDecimalPlaces(value) < 14 && value !== '';
}

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

Expand Down

0 comments on commit 1dce6ac

Please sign in to comment.