Skip to content

Commit

Permalink
Fix empty state for currency inputs in product editor (woocommerce#38697
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joshuatf authored Jun 15, 2023
1 parent bfd720c commit ce770bb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/js/product-editor/changelog/fix-38623
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Fix empty state for currency inputs in product editor
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const useCurrencyInputProps = ( {
}
},
onChange( newValue: string ) {
const sanitizeValue = sanitizePrice( newValue || '0' );
const sanitizeValue = sanitizePrice( newValue );
if ( onChange ) {
onChange( sanitizeValue );
}
Expand Down
4 changes: 4 additions & 0 deletions packages/js/product-editor/src/hooks/use-product-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ export function useProductHelper() {
*/
const sanitizePrice = useCallback(
( price: string ) => {
if ( ! price.length ) {
return '';
}

const { getCurrencyConfig } = context;
const { decimalSeparator } = getCurrencyConfig();
// Build regex to strip out everything except digits, decimal point and minus sign.
Expand Down

0 comments on commit ce770bb

Please sign in to comment.