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.

Hidden MenuItem in MenuList causes props warning

See original GitHub issue

When a MenuList has a MenuItem wrapped by Hidden, a warning is generated.

Failed prop type: The following properties are not supported: tabIndex, onFocus. Please remove them.

I believe MenuList sets those properties, so even if I wanted to not set them they would get set.

  • This is a v1.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

A few issues are similar, but not exactly this issue: #12302 #12159 #11467.

Expected Behavior

The MenuItem should display on the correct screen resolution without producing warnings.

Current Behavior

The MenuItem produces warnings.

Steps to Reproduce

Link: https://codesandbox.io/s/y2vnzl1m8v

For example:

<MenuList role="menu">
  <Hidden smUp>
    <MenuItem onClick={() => {}}>
      Menu Item
    </MenuItem>
  </Hidden>
  <MenuItem onClick={() => {}}>
    Menu Item
  </MenuItem>
</MenuList>

Context

I want some menu items to display on small screen sizes. On large screen sizes they will appear as buttons outside the menu.

Your Environment

Tech Version
Material-UI v1.4.3
React v16.3.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
hypnoboutiquecommented, Jul 31, 2020
import React from "react";

import { MenuItem, MenuList, useMediaQuery, useTheme } from "@material-ui/core";

const Menu = () => {
  const theme = useTheme();
  const smUp = useMediaQuery(theme.breakpoints.up("sm"));

  return (
    <MenuList role="menu">
      {smUp && <MenuItem onClick={() => {}}>Menu Item</MenuItem>}
      <MenuItem onClick={() => {}}>Menu Item</MenuItem>
    </MenuList>
  );
};
1reaction
jkrehmcommented, Aug 11, 2018

Thank you for that example. It’s very helpful.

Also, if the internal API can change so this work-around isn’t needed, even better.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hidden MenuItem in MenuList causes props warning #12468
When a MenuList has a MenuItem wrapped by Hidden, a warning is generated. Failed prop type: The following properties are not supported: tabIndex ......
Read more >
How do I show which item in the Menu List is selected with ...
So the solution is to check if the current location(url) is matched with the menu item's target url. If matched, the selected prop...
Read more >
MenuItem API - Material UI - MUI
Name Type Default autoFocus bool false children node classes object
Read more >
Menu Button - Reach UI
MenuItem element props​​ All props are spread to the underlying element. In this example the onFocus prop is passed down to the element....
Read more >
MenuItem - React menu component - szhsin/react-menu
It makes the menu list scrollable or hidden when there is not enough ... Warning: don't update this prop in rapid succession, which...
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