-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[NumberField] Setting null to value does not reset to blank state #2216
Comments
@LFDanLu - sorry I couldn't directly assign to you. Pinging you in comment and leaving a comment in our Slack thread as well. Thanks again! |
Another line of interest: https://github.com/adobe/react-spectrum/blob/main/packages/@react-stately/numberfield/src/useNumberFieldState.ts#L108 |
We'll also need to check for other areas where we do a similar NaN check and account for those as well. |
Is there a workaround for this? |
At the moment none that I know of, short of using something like patch package to patch the bug locally. EDIT: |
This is also an issue with the datePicker component see #3187. I don't think there is an equivalent |
I noticed the previous way to update a controlled value is via a useEffect hook but now it's changed to
Looks like we can solve the problem by simply adding a sanity check in L97
|
🐛 Bug Report
When using the
NumberField
component, if the implementor wants to use a controlled state to control the value ofNumberField
, passing innull
does not reset this component to the initial state.🤔 Expected Behavior
😯 Current Behavior
💁 Possible Solution
Update https://github.com/adobe/react-spectrum/blob/main/packages/@react-stately/numberfield/src/useNumberFieldState.ts#L91 so it retains the empty state if the component is used in a controlled state.
🔦 Context
NumberField
component to its initial case. A use case for example, for form validation. If user resets the form and we have a parentForm
component that holds all the values of the form components, we want to reset it to the original empty value.null
tovalue
prop would result in 0, which can be a valid value and does not tell the implementor that user has not filled this form from looking at the value. If we pass inundefined
, it looks like theNumberField
retains the previous value. (eg. user enters 5, then hits reset button which results in passingundefined
to thevalue
prop, the value shown is 5 still)💻 Code Sample
https://codesandbox.io/s/nice-moore-ochpe?file=/src/App.js
🌍 Your Environment
🧢 Your Company/Team
Adobe/quarry
🕷 Tracking Issue (optional)
The text was updated successfully, but these errors were encountered: