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(input): allow number proptype on input value prop #197
Conversation
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
I'm not sure numbers work as values, if I'm not mistaken, they don't work and are transformed to strings by the dom element, so when the input changes, it's value is a string, not a number (would need to be confirmed though) |
Yeah that's right, Hendrik mentioned this as well. The thing is, I'm currently getting a number type for this field from the backend (through the data engine). So I'm getting a type warning there at the moment, since the input expects a string (it does work with a number btw.). I guess we'll have to decide which course of action we recommend:
Since the value of a number input in the onchange event is a string, I'm leaning towards the first solution, as that way we're not using multiple types for the same input, which seems confusing. |
When @ismay and I discussed this last Thursday, I was initially also leaning to the first solution as well. But one thing Ismay said made me see thing another way. Apparently where have been cases in apps where the following has happened:
So, my point is that under quite a few circumstances it's fine to be blissfully unaware of this value-type changing going on. I think most of our validators are also robust enough to deal with both numerical values of type number and string. Probably, a developer would only need to be aware of this value-type changing when he starts doing calculations based on the value, or wants to do custom validation logic. In my mind, only allowing However, allowing |
Yeah I see your point as well. I don't really have a clear preference at the moment. Leaving the app to deal with casting the number values to strings gets quite annoying and maybe a bit error prone as well (recursively mapping over an object you've received from the backend and converting the numbers to strings). edit: removed the mention of Austin, since he's on holiday. We can talk about this tomorrow, when JG is back. |
As long as the input field will always call the |
Ah, I completely forgot about that. Yeah, that seems like a proper solution to me. I'll close this then 👍 |
Good suggestion @Mohammer5 |
We currently don't allow numbers for the
Input
value
prop, if you look at the prop-types. This adds thenumber
type for<input type="number" />
.https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number