-
Notifications
You must be signed in to change notification settings - Fork 299
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/parse number locale #2435
base: master
Are you sure you want to change the base?
Fix/parse number locale #2435
Conversation
🦋 Changeset detectedLatest commit: 10fb755 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
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.
Thank you for the fix!!
I found a few minor issues. Can you have a look?
Also, please add the change log by running npm run changeset
.
packages/ui/components/localize/test/number/parseNumber.test.js
Outdated
Show resolved
Hide resolved
packages/ui/components/localize/test/number/parseNumber.test.js
Outdated
Show resolved
Hide resolved
if (options.locale) { | ||
return 'withLocale'; | ||
} | ||
if (options.mode === 'auto' && separators.length === 1) { | ||
const decimalLength = value.split(`${separators}`)[1].length; | ||
if (decimalLength >= 3) { |
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.
@gerjanvangeest, what was the idea behind this logic? Just wondering, if this logic is still relevant after introducing options.locale
.
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.
if you check line 33, with the 55.55 value the decimal length is less than 3 and the function returns ''heuristic", not "withLocale". From my point of view, if we provide the locale, it should always return the 'withLocale' mode.
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.
If you only look at the parser it might make sense to add this attribute. But if i look at the InputAmount, it is a good feature to be a bit more forgiven on the first input.
However when an amount has been formatted once, and then changed the parser could be a bit more strict.
I was thinking about adding another mode version: preformatted
.
See the draft pr: #2439
Please let me know what you think about that solution.
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.
If user changes value from 55.555 to 55.55 with the DE locale, there is a separator.
So these lines will not cover the case, right?
if (!separators || mode === 'preformatted') {
return 'withLocale';
}
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.
Its an OR, so that should work as expected.
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.
Sorry. I'm fine with this solution if it helps us to correctly format numbers with the german locale.
Also I see some pipeline is failing. Can you have a look, @vskorohod ? |
Hi @ryubro
options object should be optional. I made some changes. Could you please take a look? for browser test error:
I have no idea. It doesn't seem to be related to my changes. |
What I did