-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
[DropDownMenu] Controlled field should clear when value is undefined #1227
Conversation
Thanks @marnusw - looks like you did some cleanup on the hovered state as well? You may want to remove these lines? |
Missed those, I've removed them now too. |
Thanks @marnusw - after some more testing, it looks like this PR broke |
@@ -82,7 +82,7 @@ let SelectField = React.createClass({ | |||
}, | |||
|
|||
onChange(e, index, payload) { | |||
if (payload) { | |||
if (payload && this.props.valueMember) { | |||
e.target.value = payload[this.props.valueMember] || payload; | |||
} |
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.
The problem was on these lines. Since the SelectField
doesn't have a valueMember
prop, the payload
object was passed up in its entirety rather than the value. Checking for a valueMember
solved the issue.
However, I wonder if these three lines shouldn't be removed entirely since the same action is taken in DropDownMenu
on line 284? I also can't quite figure why the changes I made broke this. I think this might have been a hidden issue all along?
(And if valueMember
is specified on SelectField
it will be passed down to the DropDownMenu
along with the "other" props, and then it will still work as this code suggests.)
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.
Yeh, it does seem weird that SelectField
is having to handle onChange
. It seems like it should be handled in one place?
I've removed the change handler in |
[DropDownMenu] Controlled field should clear when value is undefined
Thanks @marnusw |
When
DropDownMenu
is used with a controlledSelectField
the value is updated properly except when the value isundefined
. In that case it should reset the select to the initial "unselected" state, but instead the last selection is maintained and displayed on top of the hint text. This is a patch to fix that. (I realiseDropDownMenu
will fall away eventually, but I think fixing it now is still worthwhile; this should also be outcome in any future implementation.)I also noticed that
isHovered
was maintained in theDropDownMenu
state which, as far as I could see, is never used. This caused a lot of unnecessary re-renders. I've removed that as well, but purposefully added it as the latter commit. If maintaining this status does serve some purpose I'm missing I'll just lop that one off.