s-yadav / react-number-format

React component to format numbers in an input or as a text.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to preserve the suffix in a NumericFormat when to value is empty?

CharlesCoqueret opened this issue · comments

How can I setup NumericFormat to preserve the suffix or prefix when the value is empty?
The use case is for currency.

To reproduce:
https://codesandbox.io/embed/suffice-demo-forked-tyvmpd
When the value is empty, the suffix is not displayed.

Thanks for you help.

allowEmptyFormatting is PatternFormat props. It's not a part of the NumericFormat as in most of the cases it's not intentional behaviour.

Though you can easily achieve it using our custom format. Here's the updated codesandbox.
https://codesandbox.io/s/numeric-format-allowemptyformat-zt3mh8

More on customization: https://s-yadav.github.io/react-number-format/docs/customization

Will add this on the documentation as well.

Perfect, thanks.