question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onChange returns the selected value, not the complete event

See original GitHub issue

onChange simply returns the new value and label and not the whole event.

I understand we can use the hidden input field to fire an onChange but this does not happen automatically and while we can manually fire an onChange for hidden input field, we can also wrap an event around the Select. Here is how I am doing it following #520:

<Select
  name="form-field-name"
  value={val}
  options={options}
  onChange={(val)=> {onChangeFunc({target: { name:'revision_id', value: val.value }})}}
/>

Creating an object myself and passing it to my onChange handler. Is this the right way to do it or you can suggest a better way around it?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:96
  • Comments:46 (3 by maintainers)

github_iconTop GitHub Comments

194reactions
JedWatsoncommented, Nov 20, 2019

@ashnur I’m going to address your comment for the benefit of anyone else who is seeking to understand the reasoning here, but I also want to make it clear that your language and tone is not welcome or acceptable.

First of all, this isn’t about retaining the synthetic event, I know how to do that - it’s about getting an event in the first place.

The HTML element called select does have such an event, being a HTML element. You could use the original or could create a new one.

It’s not possible to create a select component and capture an onChange event by changing its value. The event requires user interaction to fire. Faking the interaction would be significantly less predictable than choosing not to try and conform to an API that we can’t correctly implement.

If you call this a select library, that is to be used in place of that select, it is highly dishonest to say that there isn’t such an event.

There. Isn’t. Such. An. Event. There is for native select components, and if they do what you need, I wouldn’t recommend using this library.

I find it obnoxious that you suggest further propagating said leak of internals by way of one of, non-standard workarounds.

react-select is one giant non-standard workaround. It fills a gap left by the HTML spec, because native select controls are insufficient for a range of use cases; that hasn’t changed in two decades, and this is far from the first library to deal with it (prior art includes Selectize and Select2 for jQuery, you can go further back to YUI and other frameworks if you like)

It’s your implementation details that are leaking through and blocking a proper API

There’s no such thing as a “proper API”. This project is not pretending to be a native form control. If anything, the API has been designed to prevent implementation details (such as unpredictable source events) from leaking through.


Anyway, I’m done with this issue, hope the explanation and workaround helps people who come across this in the future, but I don’t maintain this project to be called dishonest or obnoxious.

191reactions
ashnurcommented, Nov 20, 2019

@JedWatson

  • thank for clarifying, even if it took you 2.5 years.
  • for the record: I called your actions what they are, I haven’t called you anything. If you can’t make this distinction, that’s not on me.
Read more comments on GitHub >

github_iconTop Results From Across the Web

OnChange event using React JS for drop down - Stack Overflow
The change event is triggered on the <select> element, not the <option> element. However, that's not the only problem.
Read more >
Handle the onChange event on a Select element in React
To handle the onChange event on a select element in React, set the `onChange` prop on the select element. Keep the value of...
Read more >
Advanced - React Select
React Select exposes a variety of eventListeners to you via props. The onchange function prop now has the following signature. (value: ValueType, action: ......
Read more >
SCR19: Using an onchange event on a select element ... - W3C
Navigate to the trigger select element, navigate through the options but do not change the value. Check that the matching option values are...
Read more >
react-select - npm
See react-select.com for live demos and comprehensive docs. ... return ( <Select value={selectedOption} onChange={this.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found