negomi / react-burger-menu

:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations
http://negomi.github.io/react-burger-menu/
MIT License
5.05k stars 586 forks source link

menu not closing on mobile #437

Closed inhyechoi closed 3 years ago

inhyechoi commented 3 years ago

When I click the menu or click outside menu on mobile the menu doesn't close.

https://github.com/inhyechoi/inhyechoi-portfolio https://inhyechoi.netlify.app/

negomi commented 3 years ago

Hi @inhyechoi,

The problem here is the markup structure in your app. The overlay (which you click on to close the menu) is rendering, but the menu is nested deeply inside your header component, so the overlay is very narrow and not covering the whole screen:

Screen Shot 2021-02-28 at 8 45 38 PM

Your app should follow the structure in the docs (and you also need to add the outer-container and page-wrap IDs to the correct elements outside the menu), so your App.js should be something like this:

<div id="outer-container" className="App" height="100%">
  // Fixed elements and menu go outside page-wrap
  <CursorFocus />
  <SocialMedia />
  <ScrollTop />
  <Menu pageWrapId={ "page-wrap" } outerContainerId={ "outer-container" } />
  <div id="page-wrap">
    // Everything else goes inside page-wrap
    <Header />
    <div className="middle">
    </div>
    <Switch>
      <Route exact path="/" component={HomePage} />
      <Route path="/projects" component={ProjectPage} />
      <Route path="/experiment" component={ExperimentPage} />
      <Route path="/designguide" component={DesignGuidePage} />
      {/* <Route component={NotFound} /> */}
    </Switch>
    <Footer /> 
  </div>
</div>

It looks like you are also trying to control the state with the isOpen prop. Here is an example of how to do that which might be helpful: https://github.com/negomi/react-burger-menu/wiki/FAQ#i-want-to-control-the-open-state-programmatically-but-i-dont-understand-how-to-use-the-isopen-prop

Hope that helps! 🙂