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.

Anchor tag in <MenuItem> doesn't work properly

See original GitHub issue

I want to be able to have a MenuItem act as an external link. Example:

  constructor() {
    super();
    this.state = { isOpen: false };
  }
  render() {
    return (
      <Wrapper
        onSelection={() => {}}
        onMenuToggle={({ isOpen }) => {
          this.setState({ isOpen });
        }}
      >
        <Button>
          Example
        </Button>
        <Menu className="dropdown-menu">
          <MenuItem
            className="dropdown-item"
            tag="a"
            href="https://example.com/"
            target="_blank"
            rel="noopener noreferrer"
          >
            Whatup
          </MenuItem>
        </Menu>
      </Wrapper>
    );
  }
}

This doesn’t work properly. Clicking the link with the mouse works fine, but selecting it with the enter key doesn’t cause the link to open. I think this package should support that. If others agree, I can make a pull request.

Browser: Google Chrome 63.0.3239.52 beta OS: Linux Mint 18.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
marcysuttoncommented, Nov 24, 2017

That’s probably because by returning you’re skipping the event.preventDefault() and allowing the link to open a URL. I’d go one step further and filter based on the target attribute in addition to tag so you don’t impact other menuitems.

I’d also add a new window icon to each item to show that URLs open in new windows so the user expects a change in context. Probably a “opens in a new window” offscreen label of some kind, as well.

0reactions
markusenglundcommented, Jan 30, 2018

Yes!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[MenuItem] Links within Menu items · Issue #204 - GitHub
Hi, I was looking at the current implementation of menu items and noticed that there is no actual link (meaning, html <a> tag)....
Read more >
Material UI Menu using routes - reactjs - Stack Overflow
I implemented LeftNav using routes, but I could not find a way to get IconMenu, or Menu working with links or routes. Anyone...
Read more >
Anchor link in menu doesn't work - Brizy Help Center
Hi, we built a website with brizy and set an anchor link in the menu to contact (Kontakt). It works - but only...
Read more >
Navigation Menu Button Example | APG | WAI - W3C
This example demonstrates the menu button design pattern for a button that displays a menu of link targets. The menu items are made...
Read more >
ARIA: menuitem role - Accessibility - MDN Web Docs
The menuitem role indicates the element is an option in a set of choices contained by a menu or menubar.
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