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 materialize css when not used with class "browser-default"

See original GitHub issue

I use materialize css framework 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>

Not sure if it’s a react issue, but maybe. I also created an issue on materialize repo: https://github.com/Dogfalo/materialize/issues/1160

Issue Analytics

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

github_iconTop GitHub Comments

23reactions
buraburecommented, Jul 21, 2015

here’s a clean way to do it:

  componentDidMount() {
    // Use Materialize custom select input
    $(this.refs.yourSelectTag).material_select(this._handleSelectChange.bind(this));
  }

if you’re using react < 0.14.0 you’ll have to use getDOMNode() on this.refs.yourSelectTag

6reactions
nanda248commented, Jun 8, 2017

_I’ve been playing around with Materialize(^0.98.2) select feature with Meteor React. Below is the way how i fixed the issue. Meteor 1.4.4.3 _

import ReactDOM from 'react-dom'; 
...
componentDidMount(){
	  $(document).ready(function() {
	    $('select').material_select();
	  });		  
	  $(ReactDOM.findDOMNode(this.refs.testSelect)).on('change',this.handleSelectChange.bind(this));
}
``
handleSelectChange(event) {
	event.preventDefault();
	var test = event.target.value;
     	       this.setState({value: test});
}

render(){
...
<div className="input-field col s12">
<select ref="testSelect">
   <option value="" disabled selected>Choose your option</option>
   <option value="123">Option 1</option>
   <option value="223">Option 2</option>
   <option value="332">Option 3</option>
</select>
    <label>Materialize Select</label>
 </div>	
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to listen on <select> change events in materialize css
I am using materialize-css with angular7. This is how I have handled this <div class ...
Read more >
Select - Materialize
Select allows user input through specified options. ... You can add the class browser-default to get the browser default. Browser Select.
Read more >
Materialize CSS Dropdowns, Working with Dropdowns in ...
Materialize CSS provides dropdown facility, it provides several CSS classes to add a dropdown list to any button. Make sure that the data-activates ......
Read more >
Team:Groningen/js/materialize - iGEM 2018
var jQuery; // Check if require is a defined function. if (typeof require ... by Materialize to confirm that Velocity is not already...
Read more >
Forms - Materialize
Materialize is a modern responsive CSS framework based on Material Design by ... <div class="input-field col s12"> <input disabled value="I am not editable" ......
Read more >

github_iconTop Related Medium Post

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