useIMask with `Number` mask initializes input with "0"
jmcolella opened this issue · comments
Describe the bug
When using the useIMask
hook and providing the Number
constructor as the mask
option, the controlled input is initialized with a value of 0
if no defaultValue is provided.
This may be due to the change introduced here, which calls the _onAccept
function when initializing the useIMask
hook.
To Reproduce
CodeSandbox
- Create a component with the
useIMask
hook with the following options:{ mask: Number }
- Attach the returned
ref
to aninput
element - Observe the rendered
input
element with a value of0
Expected behavior
When no default value is given, the useIMask
hook should not create a default value of 0
for a Number
mask.
Environment:
- OS: MacOS 12.6.5
- Browser Chrome
- Version 114.0.5735.198
- IMask version 7.0.1
Additional context
N/A
I would love for this to get resolved as I just ran into this today. If there was a possible way to just create the mask manually, I'd be okay with that. Basically allowing any number of integers with then optional decimals would be the mask
An alternative solution would be to use a regular expression.
All digits:
const { ref } = useIMask({
mask: /^[0-9]*$/,
});
Without leading zeros:
const { ref } = useIMask({
mask: /^[1-9][0-9]*$/,
});
I'm not sure why this is marked as resolved. I'm still seeing the same issue on my end.
Sorry, it seems there was a new version published to fix the issue, I will check again.
Unfortunately, the problem is still there