Skip to content

Commit

Permalink
Prevent high numbers from breaking currency inputs (woocommerce#49489)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanss authored Jul 16, 2024
1 parent 8d23ac1 commit 4dbe1c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Prevent high numbers from breaking currency inputs


Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 )
);
}
},
};
Expand Down

0 comments on commit 4dbe1c9

Please sign in to comment.