Anchor tag in <MenuItem> doesn't work properly
See original GitHub issueI 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:
- Created 6 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 thetarget
attribute in addition totag
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.
Yes!