Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Menu] Remove MenuItem dependency on ListItem #21587

Closed
2 tasks done
jedwards1211 opened this issue Jun 26, 2020 · 7 comments · Fixed by #26591
Closed
2 tasks done

[Menu] Remove MenuItem dependency on ListItem #21587

jedwards1211 opened this issue Jun 26, 2020 · 7 comments · Fixed by #26591
Labels
breaking change component: menu This is the name of the generic UI component, not the React module! design: material This is about Material Design, please involve a visual or UX designer in the process
Milestone

Comments

@jedwards1211
Copy link
Contributor

jedwards1211 commented Jun 26, 2020

A 4px margin was added to the top and bottom of ListItemText in #15339, causing an inconsistency between items that use it and items that just have a string child.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

The MenuItems in this JSX render with different heights when the viewport width >= 600:

    <MenuList>
      <MenuItem style={{ backgroundColor: "green" }}>
        without ListItemText
      </MenuItem>
      <MenuItem style={{ backgroundColor: "red" }}>
        <ListItemText>with ListItemText</ListItemText>
      </MenuItem>
    </MenuList>

image

When the viewport is narrower than 600px, a media query deactivates and their minHeight becomes 48px (ironically causing them to get taller on narrower screens...)

Expected Behavior 🤔

The menu items are the same height, like they used to be

Steps to Reproduce 🕹

https://codesandbox.io/s/blazing-resonance-oqiso?file=/src/Demo.js

Context 🔦

Discovered this working on material-ui-popup-state demos.

Your Environment 🌎

Refer to code sandbox for versions

@jedwards1211 jedwards1211 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 26, 2020
@eps1lon
Copy link
Member

eps1lon commented Jun 27, 2020

Might be safe to switch to a padding instead and see what other components are affected by it.

@eps1lon eps1lon added bug 🐛 Something doesn't work component: menu This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 27, 2020
@oliviertassinari
Copy link
Member

@jedwards1211 I don't understand, why is this an issue? Why should it behave differently?

@jedwards1211
Copy link
Contributor Author

I'm saying the two list items should not behave differently. In the past they didn't, but #15339 caused them to behave differently.

I don't know if the spec says anything about menu item height, but according to this quote from #6098 it doesn't sound like there should be any difference in height when using ListItemText vs. string children:

According to Material guidelines ALL(with controls also) single line list items must be 48px height and 40px when in dense mode. Only exception is when avatar element is present it can be 56px height.

Would reworking the minHeights and media queries on ListItem instead of using any padding or margin on the ListItemText work?

@oliviertassinari oliviertassinari removed bug 🐛 Something doesn't work good first issue Great for first contributions. Enable to learn the contribution process. labels Jun 27, 2020
@oliviertassinari
Copy link
Member

@jedwards1211 Ok, thanks for the extra information. I think that we will need to revamp the List and Menu implementation in v5. One element that has came up is that it's not a good idea to share the same style for both. So I think that we need to stop using this MenuItem > ListItem inheritance.

@oliviertassinari oliviertassinari added breaking change design: material This is about Material Design, please involve a visual or UX designer in the process labels Jun 27, 2020
@oliviertassinari oliviertassinari added this to the v5 milestone Jun 27, 2020
@jedwards1211
Copy link
Contributor Author

Okay. This issue might exist with ListItem too, I need to check.

@oliviertassinari oliviertassinari changed the title MenuItem with ListItemText vs. without has different height when viewport width >= 600px [Menu] Remove MenuItem dependency on ListItem Jan 27, 2021
@siriwatknp
Copy link
Member

@oliviertassinari for the upcoming ListItem improvement (no matter approach we take), I don't see a need to have MenuItem anymore except the a11y that it does.

// MenuItem.js
const {
    component = 'li',
    role = 'menuitem',
    tabIndex: tabIndexProp,
    ...other
  } = props;
  
  return (
    <ListItem
      role={role}
      tabIndex={tabIndex}
      component={component}
    />
  )

I see 2 ways.

  1. Deprecate MenuItem in v5, change all the docs to use new ListItemButton (based on the outcome of improvement), remove MenuItem in v6. This ways, the a11y is on the developer responsibility and we have less component to maintain.
  2. Remains MenuItem with CSS adjustment (by removing minHeight or media query) and let developer do the styling (nowadays it is easy via sx).

@oliviertassinari
Copy link
Member

@siriwatknp I think that we will always need different components for rendering a list item, a menu item, and maybe a listbox item (select). Because it works in Material Design with the same component doesn't mean it will work in most design systems. I would definitely encourage 2 without any dependency on the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: menu This is the name of the generic UI component, not the React module! design: material This is about Material Design, please involve a visual or UX designer in the process
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants