-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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
Onchange event for <select> is not propagated in materialize css when not used with class "browser-default" #3667
Comments
If you have a repro it would be great. Is "materialize" perhaps modifying the DOM? It kind of sounds like it, that's a big no-no, you may update styles and props of React managed nodes without errors, but if they're cloned/replaced/moved then it's an invariant error waiting to happen. |
I think the guilty's here https://github.com/Dogfalo/materialize/blob/master/sass/components/_form.scss#L654 materialize creates a fake select with a |
There's a lot of DOM mutation happening when you use a materialize custom component, and I guess you'll face similar problems with most of those components. Maybe Material-UI is more suitable for your requirements: http://callemall.github.io/material-ui/ |
Thank you guys! :) |
Not an actual React bug so closing out. The fact that materialize is modifying the DOM means you're probably going to have a tricky time of things and you'll probably want to build some wrapper components to make things work better. Good luck! |
Yes, but actually your answers helped me, so thanks! :) |
this isnt a react answer but materializecss ensures that when the form is submitted, the correct value is sent in the select element so if for instance you have a form (or any container) with id subject_update and the select name is type you can capture the change event with jquery as follows: |
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 |
@davidleverage You made my day! Form with id="subject_update" put me on the right track. |
Using delegated event fixes the problem for me. HTML `
Choose your option
`
JS
|
Guys, quick question. When I have dynamic children and need to bind onChangeHandler to each generated "select" component. How can I do this? Seems my ref is not unique and it just binds it to the last in my loop.. |
Hi @erudinsky I think we can simply use |
The element value is always empty for me. The options are generated dynamically, and they do appear in the list, however the node is empty when I inspect it and whatever method I use, the value is not set (i.e. |
@zpao many projects use React with Materialize. This is not an isolated case. And I'm not even sure, yet, how Materialize lists all the OPTIONS as they aren't there when I inspect my DOM.... Closing this issue on the basis that "make your own wrapper" in these circumstances is almost insulting. |
@yanickrochon Materialize replaces what React renders outside of React, that is simply not possible to support and thus there's nothing React can fix here. So Materialize is simply incompatible with React, there may be workarounds but I doubt they truly work due to the nature of Materialize, but may just hide the immediate issues and cause errors later. EDIT: PS. you can always render markup using |
@syranide Well, then, luckily some people do not agree with you, and created react-materialize which seems to solve many issues that "React [can't] fix". |
@yanickrochon That's literally what the "make your own wrapper" advice means when it's applied 😉 |
@quannt Man, thanks God I met you here. Thank you for leaving your solution, works great for me. Thanks! |
|
How can i do @nanda248 's with ref callbacks? |
|
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.When i add the class
browser-default
toselect
it works pretty well.Not sure if it's a react issue, but maybe.
I also created an issue on materialize repo: Dogfalo/materialize#1160
The text was updated successfully, but these errors were encountered: