I have made some dropdown menus:
export default class DropdownMenu extends Component {
constructor(props) {
super(props)
this.state = {
menuOpen: false,
highlight: false,
count: this.props.count | 0
}
this.showDropdown = this.showDropdown.bind(this);
}
componentDidMount() {
}
showDropdown() {
this.setState({
menuOpen: !this.state.menuOpen
});
}
render() {
return <div className="dropdown__menu" onClick={this.showDropdown}>
{this.props.text} {this.state.count > 0 ? <b>{this.state.count}</b> : ''}
<div className="dropdown__content" style={this.state.menuOpen ? {'display': 'block'} : {'display': 'none'}}>
{this.props.children}
</div>
</div>
}
}
The issue is that you can open all of them and leave them open until you click on them again to close them. How do I make it so that any other menu that is open gets closed if another is opened?
Here is where they are implemented:
render() {
...
<div className="filter_container">
<DropdownMenu text="New" count={127} disabled/>
<DropdownMenu text="Only show">
<li>New</li>
<li>Old</li>
</DropdownMenu>
<DropdownMenu text="Other">
<li>one</li>
<li>two</li>
</DropdownMenu>
<DropdownMenu text="Sort by">
<li>Name</li>
<li>Age</li>
<li>Value</li>
</DropdownMenu>
</div>
</div>
...