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.

[NavigationMenu] Menu should close when navigating to a `Link`

See original GitHub issue

Feature request

Overview

Add open state to NavigationMenu.Root so we can override opening/closing states for use with external lib (e.g. Framer Motion).

Same functionality as found in Collapsible, DropdownMenu, Dialog, etc.

Edit: There’s also no way of closing the menu when navigation between pages in a Next.js app and the menu stays open (located in global layout outside page content)

Thank you!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
samburgerscommented, Apr 21, 2022

thanks for this! i implemented a slight change to @andy-hook example, hooking into route changes rather than click events - meaning it should catch things like browser fwd/back buttons and keyboard shortcuts etc too

  const [value, setValue] = React.useState("");
  const { asPath } = useRouter();

  React.useEffect(() => {
    setValue("");
  }, [asPath]);

https://codesandbox.io/s/mystifying-germain-mlb900?file=/pages/_app.js

3reactions
andy-hookcommented, Apr 13, 2022

I could not find anything in the documentation regarding closing. Not sure if this the intended behavior and that I have to implement something for this.

@weskor This should be being handled for you out of the box to be honest so seems like an oversight on our part.

We’ll raise a fix soon but in the meantime you can control the value yourself and set it to an empty string in order to close the menu manually

https://codesandbox.io/s/distracted-gwen-domugj?file=/pages/_app.js

Hope this helps 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

html - How do I close the entire navigation when a link (nav ...
In a nutshell, I want the navigation menu to close and when a link is clicked. My HTML code <input type="checkbox" class="navigation__checkbox ...
Read more >
How to let mobile navigation menu close when link is clicked?
I would use javascript (or jQuery) to detect when the menu item is clicked and close the menu. $( '.menu-item' ).on( 'click', function(e){ ......
Read more >
Navigation Menu Button Example | APG | WAI - W3C
Activates the menu item, which is equivalent to activating the link element from which the menu item is made. Escape. Closes the menu....
Read more >
How to close a navigation menu when the page is clicked
... a working navigation menu on your website that can be opened and closed ... The event will fire when any part of...
Read more >
Closing a navigation menu in React - DEV Community ‍ ‍
Closing a navigation menu in React ... you go to a new page (or would if they weren't dummy links) and the menu...
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