feat(Dropdown): Pass object with name to onChange #581
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #218
This is a breaking change but I think it's worth it. There's currently no easy way to get the
name
of theDropdown
in theonChange
event. Normally in anonChange
theevent.target
will be the input that received the change. So in a form, for example, you can attach the same change handler to multiple elements and use the event to determine the appropriate field/value to update.For
Dropdown
that's not the case - it will likely be aDropdownItem
.The
Checkbox
is an example of a component that faces a similar issue regarding the target. In that component, theonClick
andonChange
are both called with{ name, value, checked }
. This PR updatesDropdown
to be called with{ name, value }
.I also cleaned up the naming of our internal event handler to be
handleChange
. The pattern of this project seems to be:handle<event>
for our internal handlerson<event>
is a prop that the user passes in and is called by our internal handlers if set.