Skip to content

Commit

Permalink
[Menu] Migrate to emotion, polish (#25368)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Mar 14, 2021
1 parent d3eca29 commit f9f5983
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api-docs/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
},
"name": "Menu",
"styles": { "classes": ["paper", "list"], "globalClasses": {}, "name": "MuiMenu" },
"styles": { "classes": ["root", "paper", "list"], "globalClasses": {}, "name": "MuiMenu" },
"spread": true,
"forwardsRefTo": "HTMLDivElement",
"filename": "/packages/material-ui/src/Menu/Menu.js",
Expand Down
1 change: 1 addition & 0 deletions docs/translations/api-docs/menu/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"variant": "The variant to use. Use <code>menu</code> to prevent selected items from impacting the initial focus and the vertical alignment relative to the anchor element."
},
"classDescriptions": {
"root": { "description": "Styles applied to the root element." },
"paper": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the Paper component"
Expand Down
2 changes: 2 additions & 0 deletions packages/material-ui/src/Menu/Menu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface MenuProps extends StandardProps<PopoverProps & Partial<Transiti
* Override or extend the styles applied to the component.
*/
classes?: {
/** Styles applied to the root element. */
root?: string;
/** Styles applied to the Paper component. */
paper?: string;
/** Styles applied to the List component via `MenuList`. */
Expand Down
32 changes: 17 additions & 15 deletions packages/material-ui/src/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,33 @@ const LTR_ORIGIN = {
};

const overridesResolver = (props, styles) => {
return deepmerge(styles.popover || {}, {
[`& .${menuClasses.paper}`]: styles.paper,
[`& .${menuClasses.list}`]: styles.list,
});
return deepmerge(
{
[`& .${menuClasses.paper}`]: styles.paper,
[`& .${menuClasses.list}`]: styles.list,
},
styles.root || {},
);
};

const useUtilityClasses = (styleProps) => {
const { classes } = styleProps;

const slots = {
popover: ['popover'],
root: ['root'],
paper: ['paper'],
list: ['list'],
};

return composeClasses(slots, getMenuUtilityClass, classes);
};

const MenuPopover = experimentalStyled(
const MenuRoot = experimentalStyled(
Popover,
{ shouldForwardProp: (prop) => shouldForwardProp(prop) || prop === 'classes' },
{
name: 'MuiMenu',
slot: 'Popover',
slot: 'Root',
overridesResolver,
},
)({});
Expand Down Expand Up @@ -93,8 +96,8 @@ const Menu = React.forwardRef(function Menu(inProps, ref) {
PaperProps = {},
PopoverClasses,
transitionDuration = 'auto',
variant = 'selectedMenu',
TransitionProps: { onEntering, ...TransitionProps } = {},
variant = 'selectedMenu',
...other
} = props;

Expand All @@ -103,11 +106,11 @@ const Menu = React.forwardRef(function Menu(inProps, ref) {
autoFocus,
disableAutoFocusItem,
MenuListProps,
onEntering,
PaperProps,
transitionDuration,
variant,
onEntering,
TransitionProps,
variant,
};

const classes = useUtilityClasses(styleProps);
Expand All @@ -117,8 +120,6 @@ const Menu = React.forwardRef(function Menu(inProps, ref) {
const menuListActionsRef = React.useRef(null);
const contentAnchorRef = React.useRef(null);

const getContentAnchorEl = () => contentAnchorRef.current;

const handleEntering = (element, isAppearing) => {
if (menuListActionsRef.current) {
menuListActionsRef.current.adjustStyleForScrollbar(element, theme);
Expand Down Expand Up @@ -187,8 +188,8 @@ const Menu = React.forwardRef(function Menu(inProps, ref) {
});

return (
<MenuPopover
getContentAnchorEl={getContentAnchorEl}
<MenuRoot
getContentAnchorEl={() => contentAnchorRef.current}
classes={PopoverClasses}
onClose={onClose}
anchorOrigin={isRtl ? RTL_ORIGIN : LTR_ORIGIN}
Expand All @@ -201,6 +202,7 @@ const Menu = React.forwardRef(function Menu(inProps, ref) {
root: classes.paper,
},
}}
className={classes.root}
open={open}
ref={ref}
transitionDuration={transitionDuration}
Expand All @@ -219,7 +221,7 @@ const Menu = React.forwardRef(function Menu(inProps, ref) {
>
{items}
</MenuMenuList>
</MenuPopover>
</MenuRoot>
);
});

Expand Down
9 changes: 4 additions & 5 deletions packages/material-ui/src/Menu/Menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ describe('<Menu />', () => {
muiName: 'MuiMenu',
refInstanceof: window.HTMLDivElement,
testDeepOverrides: { slotName: 'list', slotClassName: classes.list },
testRootOverrides: { slotName: 'popover', slotClassName: classes.popover },
testRootOverrides: { slotName: 'root', slotClassName: classes.root },
testVariantProps: { variant: 'menu' },
skip: [
'rootClass', // the root is portal
'componentProp',
'componentsProp',
// react-transition-group issue
'reactTestRenderer',
'themeDefaultProps',
'themeStyleOverrides',
'reactTestRenderer', // react-transition-group issue
'themeDefaultProps', // the root is portal
],
}));

Expand Down
3 changes: 3 additions & 0 deletions packages/material-ui/src/Menu/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export { default } from './Menu';
export * from './Menu';

export { default as menuClasses } from './menuClasses';
export * from './menuClasses';
2 changes: 1 addition & 1 deletion packages/material-ui/src/Menu/menuClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export function getMenuUtilityClass(slot) {
return generateUtilityClass('MuiMenu', slot);
}

const menuClasses = generateUtilityClasses('MuiMenu', ['paper', 'list']);
const menuClasses = generateUtilityClasses('MuiMenu', ['root', 'paper', 'list']);

export default menuClasses;
8 changes: 3 additions & 5 deletions packages/material-ui/src/Modal/Modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ describe('<Modal />', () => {
refInstanceof: window.HTMLDivElement,
testVariantProps: { hideBackdrop: true },
skip: [
'rootClass',
'rootClass', // the root is portal
'componentProp',
'componentsProp',
// Can not test this because everything is applied to second element
'themeDefaultProps',
'themeDefaultProps', // the root is portal
'themeStyleOverrides',
// https://github.com/facebook/react/issues/11565
'reactTestRenderer',
'reactTestRenderer', // https://github.com/facebook/react/issues/11565
],
}),
);
Expand Down
5 changes: 2 additions & 3 deletions packages/material-ui/src/Popover/Popover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ describe('<Popover />', () => {
skip: [
'componentProp',
'componentsProp',
'themeDefaultProps',
'themeDefaultProps', // the root is portal
'themeStyleOverrides',
'themeVariants',
// react-transition-group issue
'reactTestRenderer',
'reactTestRenderer', // react-transition-group issue
],
}));

Expand Down

0 comments on commit f9f5983

Please sign in to comment.