Chakra-ui: [Menu] closeOnSelect not working on navigation w/ next.js links

Created on 3 Feb 2020  路  3Comments  路  Source: chakra-ui/chakra-ui

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

Bug 馃悰 workaround available 鉁岋笍

Most helpful comment

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>

All 3 comments

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>

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

ah ok got it, pass down ref!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Machinezero picture Machinezero  路  3Comments

snack-0verflow picture snack-0verflow  路  3Comments

Calvein picture Calvein  路  3Comments

ianstormtaylor picture ianstormtaylor  路  3Comments

nainardev picture nainardev  路  3Comments