mantinedev / mantine

A fully featured React components library
https://mantine.dev
MIT License
26.92k stars 1.9k forks source link

[@mantine/core] NumberInput: Error #799

Closed converter-user-old closed 2 years ago

converter-user-old commented 2 years ago

What package has an issue

@mantine/core

Describe the bug

If you have a custom decimalSeparator and remove all numbers from the input, an error occurse

In which browser did the problem occur

All

If possible, please include a link to a codesandbox with the reproduced problem

https://mantine.dev/core/number-input/#decimal-separator

Do you know how to fix the issue

Yes

Are you willing to participate in fixing this issue and create a pull request with the fix

No

Possible fix

Add to the replace a ?: https://github.com/mantinedev/mantine/blob/62c1b7e00352731988160321b4369f2731668b28/src/mantine-core/src/components/NumberInput/NumberInput.tsx#L143

parsedStr = parsedStr?.replace(/\./g, decimalSeparator); 

probably to this to: https://github.com/mantinedev/mantine/blob/62c1b7e00352731988160321b4369f2731668b28/src/mantine-core/src/components/NumberInput/NumberInput.tsx#L153

num = num?.replace(new RegExp(`\\${decimalSeparator}`, 'g'), '.');
rtivital commented 2 years ago

Thanks for reporting!

frkozbk commented 2 years ago

Hi @rtivital, The problem is if a user deletes everything, text input sends "undefined". I added the default value to "formatNum". Right now if we delete everything it stays empty I don't know if this is correct behavior or not. Lmk if you want me to change anything.

https://github.com/mantinedev/mantine/pull/802 (i usually don't contribute so sorry if I did something wrong also thank you for this UI library it is really good)

converter-user-old commented 2 years ago

Fixed in 3.6.7