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] Use ButtonBase in MenuItem #26591

Merged
merged 67 commits into from
Jun 16, 2021
Merged

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jun 4, 2021

BREAKING CHANGES

  • Change the default value of anchorOrigin.vertical to follow the Material Design guidelines. The menu now displays below the anchor instead of on top of it.
    This conversation was marked as resolved by siriwatknp
    Show conversation
    You can restore the previous behavior with:

     <Menu
    +  anchorOrigin={{
    +    vertical: 'top',
    +    horizontal: 'left',
    +  }}
  • The MenuItem component inherits the ButtonBase component instead of ListItem.
    The class names related to "MuiListItem-*" are removed and theming ListItem is no longer affecting MenuItem.

    -<li className="MuiButtonBase-root MuiMenuItem-root MuiListItem-root">
    +<li className="MuiButtonBase-root MuiMenuItem-root">
  • prop listItemClasses is removed, use classes instead.

    -<MenuItem listItemClasses={{...}}>
    +<MenuItem classes={{...}}>

Preview: https://deploy-preview-26591--material-ui.netlify.app/components/menus/

Changes

  • replace ListItem with ButtonBase in MenuItem

  • add 3 more demos (IconMenu, DenseMenu and AccountMenu)

  • overrides nested component when compose together to have good looking by default

    • ListItemIcon
    • ListItemText
    • Divider
  • height of MenuItem

    dense xs sm (up)
    true 36px 36px
    false 48px 36px

    ListItem also has 36px with dense: true

The reason I add css to override multiple component because I think this is MenuItem's responsibility to provide good looking by default (follow Material Design). If developers needs highly customisation, they can skip MenuItem and build from ListItemButton instead.

same markup

v4

image

https://codesandbox.io/s/material-demo-forked-o84t1?file=/demo.tsx

v5

image

@siriwatknp
Copy link
Member Author

How about converting what we had in v4?

updated. https://deploy-preview-26591--material-ui.netlify.app/components/menus/#positioned-menu

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a breaking changes section in migration-v4.md

@siriwatknp
Copy link
Member Author

siriwatknp commented Jun 11, 2021

Let's add a breaking changes section in migration-v4.md

It is added to migration-v4.md in MenuItem section

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 12, 2021

@siriwatknp We are off-topic with this discussion but it's still interesting for the future. It makes me think about #9893 that we talked about with @eps1lon at some point. It seems that what you are expecting is the menu button to keep the focus when the popup opens.

Take a look at google docs.

From what I understand, Google Docs implements the menu (AKA menu bar) pattern: https://www.w3.org/TR/wai-aria-practices/#menu. The <Menu> implements the menu button pattern: https://www.w3.org/TR/wai-aria-practices/#menubutton.

why the grey color cover the second menu.

Because when you click to open, the first menu item is focused, if press Enter, it activates this first option. You will find the same behavior here: https://stripe.com/docs/.

stripe

@siriwatknp siriwatknp requested a review from mnajdova June 14, 2021 04:40
docs/src/pages/components/menus/menus.md Outdated Show resolved Hide resolved
docs/src/pages/guides/migration-v4/migration-v4.md Outdated Show resolved Hide resolved
packages/material-ui/src/Menu/Menu.js Show resolved Hide resolved
packages/material-ui/src/MenuItem/MenuItem.d.ts Outdated Show resolved Hide resolved
Comment on lines +49 to +52
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;

Same as previous?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If removed, it is all gone from docs api and proptype. Let's keep it for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think on the docs there is info that it extends some interface, so that should be enough.

Copy link
Member Author

@siriwatknp siriwatknp Jun 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But Button, IconButton and ListItemButton also has sx in there d.ts file, should we keep the same for MenuItem? not really sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s keep it, but leave this conversation open, so that we can address it later.

Co-authored-by: Marija Najdova <mnajdova@gmail.com>
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't notice anything else 👍

packages/material-ui/src/MenuItem/menuItemClasses.ts Outdated Show resolved Hide resolved
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

```diff
-<li className="MuiButtonBase-root MuiMenuItem-root MuiListItem-root">
+<li className="MuiButtonBase-root MuiMenuItem-root">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add this BC:

image

And please update the PR description as well :)

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last comment for polishing the breaking changes description, apart from that looks good 👍

Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great summary description 👍

Just have some typos

docs/src/pages/components/menus/menus.md Outdated Show resolved Hide resolved
docs/src/pages/components/menus/menus.md Outdated Show resolved Hide resolved
Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
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
5 participants