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 event for <select> is not propagated in react when not used with class "browser-default"

See original GitHub issue

I use materialize with react and had an issue on <select>s onChange event propagation. This way the event is not fired, this.handleSelectChange is not called.

<select value="B" onChange={this.handleSelectChange}>
    <option value="A">Apple</option>
    <option value="B">Banana</option>
    <option value="C">Cranberry</option>
</select>

When i add the class browser-default to select it works pretty well.

<select className="browser-default" value="B" onChange={this.handleSelectChange}>
    <option value="A">Apple</option>
    <option value="B">Banana</option>
    <option value="C">Cranberry</option>
</select>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
kriscarlecommented, Aug 14, 2015

Based on comments in the other thread, I worked around this with the code below:

handleSelectChange(event) {
     setState({value: event.target.value});
   },

componentDidMount() {
     $(React.findDOMNode(this.refs.mySelectBox)).on('change',this.handleSelectChange);
   },

render() {
   return (
    ...
      <select ref="mySelectBox" value={this.state.value}>
    ...
   )
}

1reaction
SimHackercommented, Jan 20, 2017

This is probably caused by the fact that selects often ignore user input, as described in this bug report I filed: https://github.com/Dogfalo/materialize/issues/4098

Please re-open that issue, and mark this as a duplicate. I described and fixed an input event tracking problem that causes select menus to ignore the item you select, if you don’t click on it very quickly, or if you press down and drag.

To demonstrate this, try popping up the menu by clicking (because pressing and dragging does not work, and starts a text selection gesture, which is another bug), then point at an item different than the currently selected item, then click very quickly. If you click quickly enough, it works. Then try clicking on another item than the one you just selected, but more slowly so you’re holding the button or finger down for about half a second to a second. (Not a press-and-hold gesture, which is slower, but just a slow click, which is very common for people to do.) Notice that the menu pops down at the instant you press down on the button or touch the screen, but the onclick handler that reports the selected item is never called. That is the bug I reported and fixed, but it was closed unfortunately because the developers don’t see it as a bug. But it certainly is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Onchange event for <select> is not propagated in materialize ...
I use materialize css framework with react and had an issue on <select> s onChange event propagation. This way the event is not...
Read more >
Developers - Onchange event for <select> is not propagated in ...
I use materialize css framework with react and had an issue on <select> s onChange event propagation. This way the event is not...
Read more >
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 >
Handling Events :: Eloquent JavaScript
You can use this property to ensure that you're not accidentally handling something that propagated up from a node you do not want...
Read more >
SyntheticEvent - React
The synthetic events are different from, and do not map directly to, the browser's ... false from an event handler will no longer...
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