From ce770bbfd21db22ff84f96a191868d3661c6ebfa Mon Sep 17 00:00:00 2001 From: Joshua T Flowers Date: Thu, 15 Jun 2023 09:32:57 -0700 Subject: [PATCH] Fix empty state for currency inputs in product editor (#38697) --- packages/js/product-editor/changelog/fix-38623 | 4 ++++ .../js/product-editor/src/hooks/use-currency-input-props.ts | 2 +- packages/js/product-editor/src/hooks/use-product-helper.ts | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 packages/js/product-editor/changelog/fix-38623 diff --git a/packages/js/product-editor/changelog/fix-38623 b/packages/js/product-editor/changelog/fix-38623 new file mode 100644 index 00000000000..7f2a88a4405 --- /dev/null +++ b/packages/js/product-editor/changelog/fix-38623 @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Fix empty state for currency inputs in product editor diff --git a/packages/js/product-editor/src/hooks/use-currency-input-props.ts b/packages/js/product-editor/src/hooks/use-currency-input-props.ts index f92e141bae7..b4aabcd0d09 100644 --- a/packages/js/product-editor/src/hooks/use-currency-input-props.ts +++ b/packages/js/product-editor/src/hooks/use-currency-input-props.ts @@ -81,7 +81,7 @@ export const useCurrencyInputProps = ( { } }, onChange( newValue: string ) { - const sanitizeValue = sanitizePrice( newValue || '0' ); + const sanitizeValue = sanitizePrice( newValue ); if ( onChange ) { onChange( sanitizeValue ); } diff --git a/packages/js/product-editor/src/hooks/use-product-helper.ts b/packages/js/product-editor/src/hooks/use-product-helper.ts index b55178bd511..fc8da5d5a02 100644 --- a/packages/js/product-editor/src/hooks/use-product-helper.ts +++ b/packages/js/product-editor/src/hooks/use-product-helper.ts @@ -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.