My requirement is very simple. i am using materialize css dropdown pluggin. which is similar to bootstrap dropdown. Basically, I wrote a React component which renders the template of the dropdown. After rendering, in componentDidMount function I am initializing dropdown using materialize pluggin.
My Component Render Function:-
render: function () {
var that = this;
return (
<div>
<a ref="addComponent" className="add-component dropdown-button btn-floating btn-large waves-effect waves-light grey" data-activates='dropdown1'>
<i className="mdi-content-add"></i>
</a>
<ul id='dropdown1' className='dropdown-content'>
{
this.state.items.map(function (item, index) {
return <li key={index} onClick={that.triggerEvent.bind(null, item)}>{item}</li>
})
}
</ul>
</div>
);
}
ComponentDidMount function ;-
componentDidMount: function () {
var that = this;
var component = $(this.refs.addComponent.getDOMNode());
setTimeout(function () {
component.dropdown({
inDuration: 300,
outDuration: 225,
constrain_width: false, // Does not change width of dropdown to that of the activator
hover: false, // Activate on click
alignment: 'left', // Aligns dropdown to left or right edge (works with constrain_width)
gutter: 0, // Spacing from edge
belowOrigin: false // Displays dropdown below the button
}
);
})
}
My Dropdown list initialized in getInitialState function :-
getInitialState: function () {
return {
items: ["Item1", "Item2", "Item3"]
}
}
Whenever i click the button dropdown is opening. After that, if i select any item, click event handler is not triggering. please check the event handler registration in render function.
<li key={index} onClick={that.triggerEvent.bind(null, item)}>{item}</li>
I am getting the following error in console
Uncaught Error: Invariant Violation: findComponentRoot(..., .0.1.$1): Unable to find element. This probably means the DOM was unexpectedly mutated (e.g., by the browser), usually due to forgetting a when using tables, nesting tags like ,
, or , or using non-SVG elements in an parent. Try inspecting the child nodes of the element with React ID
Please check the jdfiddle for more details http://jsfiddle.net/pashaplus/3u9xug0b/