-
Notifications
You must be signed in to change notification settings - Fork 71
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
NumberInput: Add decimal type and currency #2634
Conversation
❌ Deploy Preview for moduswebcomponents failed. Why did it fail? →
|
stencil-workspace/src/components/modus-number-input/modus-number-input.tsx
Show resolved
Hide resolved
stencil-workspace/src/components/modus-number-input/modus-number-input.spec.ts
Show resolved
Hide resolved
Including the cleave-zen library the input is required to have type text , hence the aria attributes like
are not valid , so can we remove them or is their any alternative? @coliff |
Yep, please remove them. They are not valid. Thanks! |
Removed them. |
The number input PR is good in many ways, but I have some concerns...
I think to summarize, I think the defaults should be like what they were before and new functionality should be opt-in.... otherwise it could cause breaking changes / unintended side effects for users web apps. |
|
That is a better name , can we go with |
I think we should be using the Intl.NumberFormat standard js object to handle formatting. The end user would provide a locale and the number format options. I was looking at this library https://dm4t2.github.io/intl-number-input/guide/#installation but i wasn't keen on the format as you type aspect of it... but thats just my opinion. If there was a way to use this library without the live formatting it would be great... otherwise it might be easier to just handle it ourselves. I'm open to using another library if one is found as well that wraps the functionality in a useful way. I just felt the picked library complicated the end user experience too much. I'd like to reduce the complexity for the end user as we should expect that they will have or otherwise obtain the users locale. For the component, I envision something like <modus-number-input type="currency" locale="en-US" currency="USD"></modus-number-input> behind the scenes we are creating an input with type="text" (keep it as number otherwise), and we are doing something to the affect of Intl.NumberFormat(this.locale, { style: 'currency', currency: this.currency }).format(this.value); We should probably also map any existing properties to the formatting that control the number of decimals. Additional enhancements could be to restrict them from typing more decimals than they have the precision set to... I've seen libraries take a number with decimal places like 1234.5 and do something like const formatter = new Intl.NumberFormat(this.locale);
const parts = formatter.formatToParts(1234.5);
let decimalPoint = '.';
let groupSeparator = ',';
for (const part of parts) {
if (part.type === 'decimal') {
decimalPoint = part.value;
}
if (part.type === 'group') {
groupSeparator = part.value;
}
} Once you know those, you can do cool things like prevent them from typing more than max decimal digits after the decimalPoint. Additional thoughts are that we can leverage this for a |
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.
@ElishaSamPeterPrabhu Have you tried Intl.NumberFormat or toLocalString method of Number? Also,
- Looks like we are using the text input by default for all cases, better to keep the type as number if currency and locale props are not set
- Locale & currency symbol - The accepted values need to be documented properly. Make sure the values matches with the options in toLocaleString or create an internal mapping
- Step up & down behaviors
- working in reverse when using scroll.
- Not working with keyboard up and down arrow.
- Not working without specifying locale.
- The Prop
step
is not working.
- Currency prop is not working without locale prop.
- Min & Max value prop - Behavior changed, now it accepts any number and automatically sets the respective threshold if out of range
- Cleanup code - some places in e2e have references to Cleave package which is not used now.
Merged in #2864 |
Description
References
Fixes #2440
Type of change
How Has This Been Tested?
https://deploy-preview-2634--moduswebcomponents.netlify.app/?path=/story/user-inputs-number-input--default
Checklist