Skip to content
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

[Select] Simpler onChange event.target logic #12231

Merged

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Jul 21, 2018

Closes #12205. Using event.target.dataset doesn't make much sense in this context. The target could be coming from any element that triggered the click event. People can use event.currentTarget.dataset instead.


event.target = { ...target, value, name };

The current spread syntax is pointless. The spread operator is using the iteration protocols to navigate over elements and collect the results (with arrays) or to copy enumerable properties (with objects).
But:

{...document.createElement('div')} // === {}

Instead, let's make a bold move. Yes, we try to make the event match the native change event at the cost of altering the event.

event.target = { value, name };

@oliviertassinari oliviertassinari added the component: select This is the name of the generic UI component, not the React module! label Jul 21, 2018
@rgallison
Copy link

rgallison commented Jan 16, 2024

People can use event.currentTarget.dataset instead.

Trying to do so with a TextField select and currentTarget is null. We ended up mutating the value of the options to access additional information about the option clicked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: select This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Select] onChange - accessing data-* attributes
2 participants