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.

The menu opens / closes when I click anywhere on the page

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
negomicommented, Jun 3, 2017

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 😃

1reaction
Stvadcommented, Dec 21, 2021

this is a very weird default behavior though

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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