-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: disable currency abbreviations in custom amounts #7625
base: develop
Are you sure you want to change the base?
Conversation
@JoshuaHungDinh the screen recording in the PR description suggests that the abbreviation is still used. Is that correct? |
@kjohnson I logged a couple of items coming from the input field. We are only using the value. It looks like it might replace the letter with a space in the display. |
Oh, ok, so the underlying issue was that it was interpreting the
|
@kjohnson Yea, Im not the biggest fan of the formatted display not reintroducing the proper group separator. There was another suggestion to calculate the group and decimal separators outside of react-currency-input & then provide them to the component as props. I've updated this PR to include both suggestions. |
@JoshuaHungDinh is this a second, related issue being addressed? |
const [decimalSeparator, setDecimalSeparator] = useState('.'); | ||
|
||
useEffect(() => { | ||
const formatter = new Intl.NumberFormat(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will override the browser's locale and assume a US locale for separators.
While is does prevent the NaN
issue, we shouldn't do so by locking the local config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I don't think we need a hook for this, since the value shouldn't change after page load. Instead, we could initialize these variables at the top of the component file,
import ...
const formatter = new Intl.NumberFormat();
// ...
const Component = () => {
// ...
}
export default Component;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoshuaHungDinh I updated this to use the browser locale configuration and replaced the non-breaking space on the group separator to avoid any conflicts with the suffix separator used by the <CurrencyInput />
component.
const formatter = new Intl.NumberFormat(navigator.language);
const groupSeparator = formatter.format(1000).replace(/[0-9]/g, '');
const decimalSeparator = formatter.format(1.1).replace(/[0-9]/g, '');
//
groupSeparator={
/**
* Replace non-breaking space to avoid conflict with the suffix separator.
* @link https://github.com/cchanxzy/react-currency-input-field/issues/266
*/
groupSeparator.replace(/\u00A0/g, ' ')
}
//
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, these changes make sense.
Thanks for helping me move this forward. I'll send it to QA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoshuaHungDinh good job researching the underlying conflict!
Build for QA, see https://github.com/impress-org/givewp/actions/runs/12205301456. |
Resolves #7537
Resolves GIVE-1985
Description
References:
cchanxzy/react-currency-input-field#255
https://github.com/cchanxzy/react-currency-input-field#abbreviations
Some languages in certain browsers update the
CustomAmount
on forms with abbreviated letters for the value. This results in an issue where the input can renderNaN
& adds "000" for every additional 0 included.This PR addresses the issue by disabling the abbreviations.
Affects
Donation Forms
Visuals
Disable Abbreviations
Screen.Recording.2024-11-15.at.6.58.00.AM.mov
With calculated separators
Screen.Recording.2024-11-21.at.10.51.33.AM.mov
Testing Instructions
NaN
errors do not occur.Pre-review Checklist