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] Allow links as MenuItems

See original GitHub issue

Description

Currently, there is no clear way to render anchors as menu items. Existing MenuItem strongly assumes that it’s going to render a button element: https://github.com/chakra-ui/chakra-ui/blob/910a701f9f3b16157f287479a3df64a2ea84090b/packages/menu/src/menu.tsx#L259

Problem Statement/Justification

This is a valid use case, implemented as an example here: https://www.w3.org/TR/wai-aria-practices-1.2/examples/menu-button/menu-button-links.html

Proposed Solution or API

Either provide an option on the MenuItem (could be indirect) or create a new MenuItemLink component. An example in the docs of how to use this would be appreciated as well.

Alternatives

No response

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

16reactions
Andaristcommented, Dec 30, 2021

I think this works OK:

<Menu>
    <MenuButton>Working menu</MenuButton>
    <MenuList>
        <NextLink href="/" passHref>
            <MenuItem as="a">Home</MenuItem>
        </NextLink>
        <NextLink href="/about" passHref>
            <MenuItem as="a">About</MenuItem>
        </NextLink>
        <NextLink href="/profile" passHref>
            <MenuItem as="a">Profile</MenuItem>
        </NextLink>
    </MenuList>
</Menu>

Can be tested here: https://codesandbox.io/s/nervous-elbakyan-2mcxs?file=/pages/_app.js

I wouldn’t call this intuitive though.

4reactions
Andaristcommented, Apr 16, 2022

bump for the stale bot

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Links to a Menu – WordPress.com Support
Under Add menu items, tick the boxes for each of the new menu items you wish to add. You can choose from Pages,...
Read more >
Menu Items & Menu Item Links : Support Center
Menu Items - Allows the User to set the details for each Menu Item including: Display Name, Estimated Cost, Price, Target Margin, etc....
Read more >
Example menu items and content links
The method for choosing a link target (current window, iFrame, or new window) and referencing the item linked (page, attachment, or URL) are...
Read more >
Navigation Menu Button Example | APG | WAI - W3C
The menu items are made from HTML links, so they maintain their HTML ... be a menuitem because accessibility APIs do not enable...
Read more >
Add a menu item that links to a page section | Beaver Builder ...
You can add a menu item whose link goes to a specific section on the same page or a section on a different...
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