Fix invalid value being propagated on change event for number input (#44195)
This commit is contained in:
parent
861cc7cc02
commit
862383e1eb
|
@ -0,0 +1,5 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
Comment: Fix invalid value being propagated on change event for number input
|
||||
|
||||
|
|
@ -19,6 +19,8 @@ type Props = {
|
|||
onKeyDown?: ( event: React.KeyboardEvent< HTMLInputElement > ) => void;
|
||||
};
|
||||
|
||||
const NOT_NUMBERS_OR_SEPARATORS_REGEX = /[^0-9,.]/g;
|
||||
|
||||
export const useNumberInputProps = ( {
|
||||
value,
|
||||
onChange,
|
||||
|
@ -56,7 +58,9 @@ export const useNumberInputProps = ( {
|
|||
}
|
||||
},
|
||||
onChange( newValue: string ) {
|
||||
const sanitizeValue = parseNumber( newValue );
|
||||
const sanitizeValue = parseNumber(
|
||||
newValue.replace( NOT_NUMBERS_OR_SEPARATORS_REGEX, '' )
|
||||
);
|
||||
onChange( sanitizeValue );
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue