Fix empty state for currency inputs in product editor (#38697)

This commit is contained in:
Joshua T Flowers 2023-06-15 09:32:57 -07:00 committed by GitHub
parent bfd720c28f
commit ce770bbfd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Fix empty state for currency inputs in product editor

View File

@ -81,7 +81,7 @@ export const useCurrencyInputProps = ( {
}
},
onChange( newValue: string ) {
const sanitizeValue = sanitizePrice( newValue || '0' );
const sanitizeValue = sanitizePrice( newValue );
if ( onChange ) {
onChange( sanitizeValue );
}

View File

@ -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.