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.

Unable to close menu after clicking on link

See original GitHub issue

I’m using the menu within a “body” component that spans my whole page. I’ve added the menu as follows and I’m using react router.

var Example = React.createClass({
  showSettings: function(event) {
    event.preventDefault();
  },
  render: function() {
    return (
      <Menu right>
        <RadiumLink className="menu-item" to="/">Home</RadiumLink>
        <RadiumLink className="menu-item" to="/about">About</RadiumLink>
        <RadiumLink className="menu-item" to="/contact">Portfolio</RadiumLink>
        <RadiumLink className="menu-item" to="/contact">Contact</RadiumLink>
      </Menu>
    );
  }
}); 

and this is its parent

render: function() {
        return (
                                <div className="border" ref="frame">
                        <Example />             
                </div>
        );

If I click on a link, it loads the page just fine however, the menu remains open and I have to either use the close button or click outside the menu to close it. How can I get it to auto-close?

Thank you

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
giladbrcommented, Jul 18, 2016

I was also able to achieve that clicking an item will close the menu simply by using isOpen={false} ! Thank you! However, I tried hooking the component through Redux using the connect() function and for some reason this behaviour stopped working…

2reactions
manosimcommented, Sep 5, 2016

I have exactly the same issue with @giladbr (I’m also using redux) and I’m on version 1.10.4. I’ve set isOpen={ false } but when I click on a link the menu does not close. Any ideas?

import React from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { bubble as Menu } from 'react-burger-menu';
import Radium from 'radium';

import { logout } from '../actions';
import Logo from './logo';

let RadiumLink = Radium(Link);

export class Sidebar extends React.Component {
  logoutUser(evt) {
    event.preventDefault();
    this.props.logout();
    this.context.router.replace({pathname: '/login'});
  }

  render() {
    return (
      <Menu width={ 280 } isOpen={ false }>
        <Logo />

        <RadiumLink className="nav-link" activeClassName="active" to="/dashboard">
          <i className="fa fa-fw fa-star-o" /> <span>Dashboard</span>
        </RadiumLink>

        <RadiumLink className="nav-link" activeClassName="active" to="/projects">
          <i className="fa fa-fw fa-bell-o" /> <span>Example</span>
        </RadiumLink>
      </Menu>
    );
  }
};

Sidebar.contextTypes = {
  router: React.PropTypes.object.isRequired
};

export default connect(null, { logout })(Sidebar);

Read more comments on GitHub >

github_iconTop Results From Across the Web

Menu doesn't close after clicking link - Forum | Webflow
A solution is to add an interaction onto each link in the navbar to move the navmenu element 100% to the right. This...
Read more >
I can't close menu when click - Stack Overflow
Try to hide/show your navigation bar using css class, that will be easy and effective way to manage it. Also replace $(document).mouseup with...
Read more >
Close menu after click | WordPress.org
It's working fine for me. I have a question regarding the menu. Nowadays it is common to add an anchor link in the...
Read more >
Solved: Close mobile side menu on click (anchor link)
To fix this problem you can add add the following code at the bottom of your assets/theme.js file. $(function () ...
Read more >
In Praise of the Unambiguous Click Menu - CSS-Tricks
When visitors need more time to take in the submenu contents, they can't afford to have the menu close unexpectedly. The JavaScript is...
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