Prevent high numbers from breaking currency inputs (#49489)

This commit is contained in:
Nathan Silveira 2024-07-16 10:22:44 -03:00 committed by GitHub
parent 8d23ac11a9
commit 4dbe1c96e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Prevent high numbers from breaking currency inputs

View File

@ -27,6 +27,8 @@ type Props = {
onKeyUp?: ( event: React.KeyboardEvent< HTMLInputElement > ) => void;
};
const CURRENCY_INPUT_MAX = 1_000_000_000_000_000_000.0;
export const useCurrencyInputProps = ( {
value,
onChange,
@ -72,7 +74,11 @@ export const useCurrencyInputProps = ( {
onChange( newValue: string ) {
const sanitizeValue = sanitizePrice( newValue );
if ( onChange ) {
onChange( sanitizeValue );
onChange(
Number( sanitizeValue ) <= CURRENCY_INPUT_MAX
? sanitizeValue
: String( CURRENCY_INPUT_MAX )
);
}
},
};