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.

[Menu] closeOnSelect not working on navigation w/ next.js links

See original GitHub issue

Describe the bug on-menu As shown above while selecting link which is wrapped in next/link in MenuItem, MenuList isn’t closing automatically as it does for normal links or any items in menu list

Is there any workaround/way to close menu on dynamic links selection?

Minimal Example Edit sleepy-cori-811en

Expected Behavior It should automatically close on selection

To Reproduce

  • Create menu links wrapped under next/link
  • Select any option

Suggested solution(s)

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context I think it’s happning due to next.js overtaking link component and preventing it on click so parent isn’t able to detact event

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
jhochcommented, Mar 10, 2020

I had this issue, too, but solved it using the onClose property that Menu can pass to its children. For example:

<Menu>
  {({ onClose }) => (
    <MenuList>
      <NextLink>
        <MenuItem as="a" onClick={onClose}>
          Hello World
        </MenuItem>
      </NextLink>
    </MenuList>
  )}
</Menu>
1reaction
export-mikecommented, Jun 2, 2020

Seems related, I’m finding the menu isn’t closing when I click anything other than the menu itself?

ezgif-4-6139f0850e20

https://codesandbox.io/s/exciting-moon-u64ey

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next js not closing mobile nav when click nav link
I'm using Next Js with Tailwind CSS for creating the website. Use Javascript to toggle the menu for Mobile devices. But Next Js...
Read more >
Menu - Argon Dashboard Chakra - Creative Tim
An accessible dropdown menu for the common dropdown menu button design pattern. Menu uses roving tabIndex for focus management. Import#. Chakra UI exports...
Read more >
Dropdown | Select2 - The jQuery replacement for select boxes
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and pagination (infinite scrolling) of results.
Read more >
Menu - Chakra UI
Chakra UI exports 8 components for rendering menus: ... MenuItemOption : The checkable menu item, to be used with MenuOptionGroup . import {....
Read more >
Dropdown | NextUI - Beautiful, fast and modern React UI Library
Menu . Dropdown.Section: A wrapper to group related menu items. ... important to have a unique key for each item, otherwise the disabled...
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