Replies: 1 comment 14 replies
-
Thanks for your thoughts. This is definitely a tricky situation. I think this runs into an issue where the value from onChange may not match the value the user thinks they entered. For instance, if the value entered is not parseable to a number, then some nullish value would be in the onChange and it'd only be revealed onBlur when the formatter fails or parses to something else. Instead, I'd consider always showing your fields so that users don't accidentally skip them. Users can also be prepared for all the fields they may encounter. Finally, I think hiding and showing form fields can be problematic. There wouldn't be an announcement for a screen reader necessarily for something like this. You could validate the age on submit and create an error on that field. I would also recommend a description on the numberfield which tells users the acceptable range. You could also make use of the min/max value. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, according to the documentation of NumberField the
onChange
handler is only called in theonBlur
event.This leads to unwanted behaviour in the form with appearing fields.
For example we could have a form that displays an additional field after checking the value of our NumberField.
In such a view, the user can press the next button without even seeing the additional checkbox.
This problem wouldn't occur if onChange was called on each key event.
I thought about a possible solution and I came up with something that doesn't need to change the current cursor position.
value === state.numberValue
- do nothing, not even formatting to keep the current cursor position, the formatting can be done on blurvalue !== state.numberValue
- set the numberValue and move the cursor to the end of the text(the controlled value is the most important)To make sure this works, numberValue should have a value that would be emitted with onBlur for the current inputValue state.
What do you think about this solution?
Beta Was this translation helpful? Give feedback.
All reactions