Skip to content

[Menu] Use ButtonBase in MenuItem#26591

Merged
siriwatknp merged 67 commits into
mui:nextfrom
siriwatknp:menu-item-depencency
Jun 16, 2021
Merged

[Menu] Use ButtonBase in MenuItem#26591
siriwatknp merged 67 commits into
mui:nextfrom
siriwatknp:menu-item-depencency

Conversation

@siriwatknp

@siriwatknp siriwatknp commented Jun 4, 2021

Copy link
Copy Markdown
Member

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 and others added 30 commits May 25, 2021 15:20
@siriwatknp

Copy link
Copy Markdown
Member Author

Comment thread packages/material-ui/src/MenuItem/MenuItem.js

@mnajdova mnajdova left a comment

Copy link
Copy Markdown
Member

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

siriwatknp commented Jun 11, 2021

Copy link
Copy Markdown
Member Author

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

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

@oliviertassinari

oliviertassinari commented Jun 12, 2021

Copy link
Copy Markdown
Member

@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
Comment thread docs/src/pages/components/menus/menus.md Outdated
Comment thread docs/src/pages/guides/migration-v4/migration-v4.md
Comment thread docs/src/pages/guides/migration-v4/migration-v4.md Outdated
Comment thread packages/material-ui/src/Menu/Menu.js
Comment thread packages/material-ui/src/MenuItem/MenuItem.d.ts Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@siriwatknp siriwatknp Jun 15, 2021

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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.

@oliviertassinari oliviertassinari left a comment

Copy link
Copy Markdown
Member

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 👍

Comment thread packages/material-ui/src/MenuItem/menuItemClasses.ts Outdated

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

Copy link
Copy Markdown
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 :)

@mnajdova mnajdova left a comment

Copy link
Copy Markdown
Member

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 👍

@eps1lon eps1lon left a comment

Copy link
Copy Markdown
Member

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

Comment thread docs/src/pages/components/menus/menus.md Outdated
Comment thread docs/src/pages/components/menus/menus.md Outdated
Co-authored-by: Sebastian Silbermann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Introduces changes that are not backward compatible. design: material This is about Material Design, please involve a visual or UX designer in the process scope: menu Changes related to the menu.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Menu] Remove MenuItem dependency on ListItem CenteredListItemIcon [MenuItem] spacing between ListItemIcon and ListItemText

5 participants