-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
Description
When using withHookFormMask with the brl-currency mask and unmaskAsNumber: true, decimal values like 0.5 are incorrectly converted to 5 in the onBeforeMask callback.
Steps to Reproduce
- Set up a form field with
withHookFormMaskusingbrl-currencymask - Configure with
unmaskAsNumber: true - Add an
onBeforeMaskcallback to log the values - Enter a decimal value like
0.5 - Observe the logged values in
onBeforeMask
Expected Behavior
- Input:
0.5→onBeforeMaskshould receive"0.5"→ Final value should be0.5
Actual Behavior
- Input:
0.5→onBeforeMaskreceives"0.5"initially → Then receives"5"→ Final value becomes5
Code Example
const inputProps = withHookFormMask(register, 'brl-currency', {
autoUnmask: true,
removeMaskOnSubmit: true,
rightAlign: false,
unmaskAsNumber: true,
onBeforeMask: (initialValue, opts) => {
console.log('[withHookFormMask] onBeforeMask', { initialValue, opts });
// initialValue changes from "0.5" to "5" unexpectedly
return initialValue;
}
});Console Output
[withHookFormMask] onBeforeMask { initialValue: '0.5', opts: {...} }
[withHookFormMask] onBeforeMask { initialValue: '5', opts: {...} }
[withHookFormMask] onBeforeMask { initialValue: '5', opts: {...} }
Environment
- Library Version:
use-mask-input(latest) - React Version: 19.1.0
- Node Version: (your node version)
- Browser: (your browser)
Additional Context
- This issue specifically affects decimal values when using
unmaskAsNumber: true - The problem occurs with the
brl-currencymask (Brazilian Real format) - Values like
0.5,0.25,0.75all get converted incorrectly - The issue doesn't occur when
unmaskAsNumber: false
Workaround
Currently using unmaskAsNumber: false and manually converting the string value to number when needed, but this defeats the purpose of the unmaskAsNumber option.
Impact
This bug makes the library unusable for currency inputs that need to handle decimal values correctly, which is a common use case for financial applications.
Additional Information
- The bug seems to be related to how the
brl-currencymask processes decimal separators - The issue occurs during the masking process, not in the final output
- This affects Brazilian Real currency formatting where comma (
,) is used as decimal separator
Metadata
Metadata
Assignees
Labels
No labels