The menu opens / closes when I click anywhere on the page
See original GitHub issueI can’t seem to figure out how to prevent the menu from opening when I click anywhere in the window. I’m still new to react and I’m currently building my first SPA so I may be missing something obvious but I want the page to behave similar to your demo site http://negomi.github.io/react-burger-menu/. I want to link the isOpen={ toggleMenu }
to a custom button with an onClick and have that be the only way to trigger the menu.
constructor(props) {
super(props);
this.state = ({toggleMenu: true});
this.handleToggleMenuClick = this.handleToggleMenuClick.bind(this);
}
showSettings (event) {
event.preventDefault();
}
handleToggleMenuClick() {
this.setState({toggleMenu: !this.state.toggleMenu});
}
<div id="outer-container" >
<CountdownBar />
<Menu noOverlay pageWrapId={ "page-wrap" } outerContainerId={ "outer-container" } isOpen={ this.state.toggleMenu }>
<Row className="show-grid">
<p>This is only a test</p>
</Row>
</Menu>
<main id="page-wrap">
<Button type="submit" onClick={this.handleToggleMenuClick} bsStyle="primary" className="btnHeight" block>
{this.state.toggleMenu ? 'Open' : 'Closed'}
</Button>
</main>
</div>
Any guidance you’re willing to offer is much appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Close menu when clicking anywhere in the document body ...
I have a menu that opens when the user clicks the icon. I want the menu to close when the user clicks anywhere...
Read more >Windows 10: When I open my start menu it just closes itself
Close start menu using the icon. Click anywhere other than the task bars. (e.g. an open window, the desktop, even the first monitor's...
Read more >The “off” click - codeburst
You click the menu button to open the menu. When you go to click off it, you expect it to close. It shouldn't...
Read more >can close menu by clicking anywhere in the navbar? - General ...
Hi Guys, I have a small issue. My menu operates fine but when in tablet view down I click the hamburger menu to...
Read more >Menu component - Vuetify
Try right-clicking anywhere on the image. ... can configure whether v-menu should be closed when its content is clicked. ... Open on hover....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Have you applied any styles?
It sounds like the burger icon is there, but invisible, and taking up the entire screen because you haven’t given it a size/background color yet.
Check out the docs on styling: https://github.com/negomi/react-burger-menu/blob/master/README.md#styling
You probably want to inspect the HTML in the console to see what elements are being rendered - this should help you debug by seeing what is being clicked to trigger the menu to open 😃
this is a very weird default behavior though