-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
ReactDOMSelect makeover, fix edge-case inconsistencies and remove state #2241
Conversation
Hmm, there are even more broken edge-cases relating to toggling multiple. One idea is to consider another case of #2242 (if you agree with it), i.e. treat But perhaps that's a bad idea and simply fixing |
Also, cc @yungsters |
This needs a rebase but I don't think that'll change much of the code... @yungsters! |
@zpao Rebased, it was just |
* @param {ReactComponent} component Instance of ReactDOMSelect | ||
* @param {?*} propValue For uncontrolled components, null/undefined. For | ||
* controlled components, a string (or with `multiple`, a list of strings). | ||
* @param {?*} propValue A string (or with `multiple`, a list of strings). |
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.
Looks like the type of propValue
should be {*}
because we should never get null or undefined with the new code, right?
Also, maybe s/string/stringable/g
.
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.
Correct and sounds good. Fixed.
Looks pretty straightforward. Couple questions inline, and I also want to clarify... besides changing the behavior of switching up |
@yungsters As for the edge-cases, the biggest ones I found where relating to the state being kept. If you told a controlled select to select 2 options and one didn't exist, if you then added that option it would not be selected. There were weird issues when toggling multiple where it would incorrectly apply old selections instead and other edge-cases of similar nature. Don't remember all of them or the specifics, I just dug deep enough to see that the state being kept was flawed and made it really hard to understand what was actually going on. |
Changes look good to me. |
Thanks for the review @yungsters! Appreciate it. |
I poached the test-case from #2289 as well then, but changed it to use |
🙏 |
ReactDOMSelect makeover, fix edge-case inconsistencies and remove state
Broken behavior discovered/encountered by #1510
EDIT: I found a handful more broken edge-cases so I decided to do a large makeover instead, simplifying the logic and removing state entirely.
I've intentionally made it "reset to default" if you toggle
multiple
because it simplified the code and I don't think it's a sane transition (browsers don't agree on what should happen either). But I could easily add it back if you disagree, but I figured it wasn't worth the size and complexity cost.As far as I'm aware, all edge-cases should be fixed now.
Previously, state would only be updated on user interaction or when togglingmultiple
. This meant that any forcedvalue
update was not remembered when togglingmultiple
or becoming uncontrolled.To solve this it has to read value duringcomponentWillReceiveProps
, whichLinkedValueUtils
couldn't do. So I updatedLinkedValueUtils
to take aprops
-object instead, which seems consistent with the direction of a reactjs-future proposal as well.grunt test
and cursory manual testingselected
attribute properly set. #2289