Skip to content

Commit

Permalink
[Menu][base-ui] Focus Menu Items on hover (#40755)
Browse files Browse the repository at this point in the history
Co-authored-by: zanivan <victorzanivan@gmail.com>
  • Loading branch information
michaldudak and zanivan authored Jan 29, 2024
1 parent 2b751cf commit 147db41
Show file tree
Hide file tree
Showing 26 changed files with 68 additions and 103 deletions.
7 changes: 1 addition & 6 deletions docs/data/base/components/menu/MenuIntroduction/css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function Styles() {
border-bottom: none;
}
.CustomMenuIntroduction--item.${menuItemClasses.focusVisible} {
.CustomMenuIntroduction--item:focus {
outline: 3px solid ${isDarkMode ? cyan[600] : cyan[200]};
background-color: ${isDarkMode ? grey[800] : grey[100]};
color: ${isDarkMode ? grey[300] : grey[900]};
Expand All @@ -121,11 +121,6 @@ function Styles() {
color: ${isDarkMode ? grey[700] : grey[400]};
}
.CustomMenuIntroduction--item:hover:not(.${menuItemClasses.disabled}) {
background-color: ${isDarkMode ? cyan[800] : cyan[50]};
color: ${isDarkMode ? grey[300] : grey[900]};
}
.TriggerButtonIntroduction {
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 600;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function Styles() {
border-bottom: none;
}
.CustomMenuIntroduction--item.${menuItemClasses.focusVisible} {
.CustomMenuIntroduction--item:focus {
outline: 3px solid ${isDarkMode ? cyan[600] : cyan[200]};
background-color: ${isDarkMode ? grey[800] : grey[100]};
color: ${isDarkMode ? grey[300] : grey[900]};
Expand All @@ -121,11 +121,6 @@ function Styles() {
color: ${isDarkMode ? grey[700] : grey[400]};
}
.CustomMenuIntroduction--item:hover:not(.${menuItemClasses.disabled}) {
background-color: ${isDarkMode ? cyan[800] : cyan[50]};
color: ${isDarkMode ? grey[300] : grey[900]};
}
.TriggerButtonIntroduction {
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 600;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const MenuItem = styled(BaseMenuItem)(
border-bottom: none;
}
&.${menuItemClasses.focusVisible} {
&:focus {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
Expand All @@ -92,11 +92,6 @@ const MenuItem = styled(BaseMenuItem)(
&.${menuItemClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${menuItemClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const MenuItem = styled(BaseMenuItem)(
border-bottom: none;
}
&.${menuItemClasses.focusVisible} {
&:focus {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
Expand All @@ -92,11 +92,6 @@ const MenuItem = styled(BaseMenuItem)(
&.${menuItemClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${menuItemClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const MenuItem = React.forwardRef((props, ref) => {
<BaseMenuItem
ref={ref}
className={clsx(
'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus-visible:shadow-outline-purple focus-visible:outline-0 focus-visible:bg-slate-100 focus-visible:dark:bg-slate-800 focus-visible-text-slate-900 focus-visible:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700 hover:bg-purple-50 hover:dark:bg-purple-950 hover:text-slate-900 hover:dark:text-slate-300',
'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus:shadow-outline-purple focus:outline-0 focus:bg-slate-100 focus:dark:bg-slate-800 focus:text-slate-900 focus:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700',
className,
)}
{...other}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const MenuItem = React.forwardRef<HTMLLIElement, MenuItemProps>((props, ref) =>
<BaseMenuItem
ref={ref}
className={clsx(
'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus-visible:shadow-outline-purple focus-visible:outline-0 focus-visible:bg-slate-100 focus-visible:dark:bg-slate-800 focus-visible-text-slate-900 focus-visible:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700 hover:bg-purple-50 hover:dark:bg-purple-950 hover:text-slate-900 hover:dark:text-slate-300',
'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus:shadow-outline-purple focus:outline-0 focus:bg-slate-100 focus:dark:bg-slate-800 focus:text-slate-900 focus:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700',
className,
)}
{...other}
Expand Down
7 changes: 1 addition & 6 deletions docs/data/base/components/menu/MenuSimple/css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function Styles() {
border-bottom: none;
}
.CustomMenuSimple--item.${menuItemClasses.focusVisible} {
.CustomMenuSimple--item:focus {
outline: 3px solid ${isDarkMode ? cyan[600] : cyan[200]};
background-color: ${isDarkMode ? grey[800] : grey[100]};
color: ${isDarkMode ? grey[300] : grey[900]};
Expand All @@ -123,11 +123,6 @@ function Styles() {
color: ${isDarkMode ? grey[700] : grey[400]};
}
.CustomMenuSimple--item:hover:not(.${menuItemClasses.disabled}) {
background-color: ${isDarkMode ? cyan[800] : cyan[50]};
color: ${isDarkMode ? grey[300] : grey[900]};
}
.TriggerButtonSimple {
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 600;
Expand Down
7 changes: 1 addition & 6 deletions docs/data/base/components/menu/MenuSimple/css/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function Styles() {
border-bottom: none;
}
.CustomMenuSimple--item.${menuItemClasses.focusVisible} {
.CustomMenuSimple--item:focus {
outline: 3px solid ${isDarkMode ? cyan[600] : cyan[200]};
background-color: ${isDarkMode ? grey[800] : grey[100]};
color: ${isDarkMode ? grey[300] : grey[900]};
Expand All @@ -123,11 +123,6 @@ function Styles() {
color: ${isDarkMode ? grey[700] : grey[400]};
}
.CustomMenuSimple--item:hover:not(.${menuItemClasses.disabled}) {
background-color: ${isDarkMode ? cyan[800] : cyan[50]};
color: ${isDarkMode ? grey[300] : grey[900]};
}
.TriggerButtonSimple {
font-family: 'IBM Plex Sans', sans-serif;
font-weight: 600;
Expand Down
7 changes: 1 addition & 6 deletions docs/data/base/components/menu/MenuSimple/system/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const MenuItem = styled(BaseMenuItem)(
border-bottom: none;
}
&.${menuItemClasses.focusVisible} {
&:focus {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
Expand All @@ -94,11 +94,6 @@ const MenuItem = styled(BaseMenuItem)(
&.${menuItemClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${menuItemClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);

Expand Down
7 changes: 1 addition & 6 deletions docs/data/base/components/menu/MenuSimple/system/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const MenuItem = styled(BaseMenuItem)(
border-bottom: none;
}
&.${menuItemClasses.focusVisible} {
&:focus {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
Expand All @@ -94,11 +94,6 @@ const MenuItem = styled(BaseMenuItem)(
&.${menuItemClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${menuItemClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]};
color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]};
}
`,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const MenuItem = React.forwardRef((props, ref) => {
<BaseMenuItem
ref={ref}
className={clsx(
'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus-visible:shadow-outline-purple focus-visible:outline-0 focus-visible:bg-slate-100 focus-visible:dark:bg-slate-800 focus-visible-text-slate-900 focus-visible:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700 hover:bg-purple-50 hover:dark:bg-purple-950 hover:text-slate-900 hover:dark:text-slate-300',
'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus:shadow-outline-purple focus:outline-0 focus:bg-slate-100 focus:dark:bg-slate-800 focus:text-slate-900 focus:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700',
className,
)}
{...other}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const MenuItem = React.forwardRef<HTMLLIElement, MenuItemProps>((props, ref) =>
<BaseMenuItem
ref={ref}
className={clsx(
'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus-visible:shadow-outline-purple focus-visible:outline-0 focus-visible:bg-slate-100 focus-visible:dark:bg-slate-800 focus-visible-text-slate-900 focus-visible:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700 hover:bg-purple-50 hover:dark:bg-purple-950 hover:text-slate-900 hover:dark:text-slate-300',
'list-none p-2 rounded-lg cursor-default select-none last-of-type:border-b-0 focus:shadow-outline-purple focus:outline-0 focus:bg-slate-100 focus:dark:bg-slate-800 focus:text-slate-900 focus:dark:text-slate-300 disabled:text-slate-400 disabled:dark:text-slate-700 disabled:hover:text-slate-400 disabled:hover:dark:text-slate-700',
className,
)}
{...other}
Expand Down
20 changes: 5 additions & 15 deletions docs/data/base/components/menu/UseMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ function Styles() {
border-bottom: none;
}
.menu-item.focus-visible {
.menu-item:focus {
background-color: ${grey[100]};
color: ${grey[900]};
outline: 0;
}
.mode-dark .menu-item.focus-visible {
.mode-dark .menu-item:focus {
background-color: ${grey[800]};
color: ${grey[300]};
}
Expand All @@ -175,19 +175,9 @@ function Styles() {
color: ${grey[400]};
}
.mode-dark .menu-item.disabled {
color: ${grey[700]};
}
.menu-item:hover:not(.disabled) {
background-color: ${grey[100]};
color: ${grey[900]};
}
.mode-dark .menu-item:hover:not(.disabled) {
background-color: ${grey[800]};
color: ${grey[300]};
}
.mode-dark .menu-item.disabled {
color: ${grey[700]};
}
.button {
font-family: 'IBM Plex Sans', sans-serif;
Expand Down
20 changes: 5 additions & 15 deletions docs/data/base/components/menu/UseMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ function Styles() {
border-bottom: none;
}
.menu-item.focus-visible {
.menu-item:focus {
background-color: ${grey[100]};
color: ${grey[900]};
outline: 0;
}
.mode-dark .menu-item.focus-visible {
.mode-dark .menu-item:focus {
background-color: ${grey[800]};
color: ${grey[300]};
}
Expand All @@ -174,19 +174,9 @@ function Styles() {
color: ${grey[400]};
}
.mode-dark .menu-item.disabled {
color: ${grey[700]};
}
.menu-item:hover:not(.disabled) {
background-color: ${grey[100]};
color: ${grey[900]};
}
.mode-dark .menu-item:hover:not(.disabled) {
background-color: ${grey[800]};
color: ${grey[300]};
}
.mode-dark .menu-item.disabled {
color: ${grey[700]};
}
.button {
font-family: 'IBM Plex Sans', sans-serif;
Expand Down
7 changes: 1 addition & 6 deletions docs/data/base/components/menu/WrappedMenuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const MenuItem = styled(BaseMenuItem)(
border-bottom: none;
}
&.${menuItemClasses.focusVisible} {
&:focus {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
Expand All @@ -122,11 +122,6 @@ const MenuItem = styled(BaseMenuItem)(
&.${menuItemClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${menuItemClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);

Expand Down
7 changes: 1 addition & 6 deletions docs/data/base/components/menu/WrappedMenuItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const MenuItem = styled(BaseMenuItem)(
border-bottom: none;
}
&.${menuItemClasses.focusVisible} {
&:focus {
outline: 3px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
Expand All @@ -116,11 +116,6 @@ const MenuItem = styled(BaseMenuItem)(
&.${menuItemClasses.disabled} {
color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]};
}
&:hover:not(.${menuItemClasses.disabled}) {
background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]};
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
}
`,
);

Expand Down
1 change: 1 addition & 0 deletions docs/pages/base-ui/api/menu-item.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"props": {
"disabled": { "type": { "name": "bool" }, "default": "false" },
"disableFocusOnHover": { "type": { "name": "bool" }, "default": "false" },
"label": { "type": { "name": "string" } },
"slotProps": {
"type": { "name": "shape", "description": "{ root?: func<br>&#124;&nbsp;object }" },
Expand Down
4 changes: 4 additions & 0 deletions docs/pages/base-ui/api/use-menu-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"required": true
},
"disabled": { "type": { "name": "boolean", "description": "boolean" } },
"disableFocusOnHover": {
"type": { "name": "boolean", "description": "boolean" },
"default": "false"
},
"id": { "type": { "name": "string", "description": "string" } },
"label": { "type": { "name": "string", "description": "string" } },
"onClick": {
Expand Down
7 changes: 1 addition & 6 deletions docs/public/static/components-gallery/base-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@
border-bottom: none;
}

.GalleryMenu-item.base--focusVisible {
.GalleryMenu-item:focus {
outline: none;
box-shadow: var(--shadow-interactive-focus-visible);
background-color: var(--bg-soft);
Expand All @@ -439,11 +439,6 @@
color: var(--font-color-soft);
}

.GalleryMenu-item:hover:not(.base--disabled) {
background-color: var(--bg-soft);
color: var(--font-color-soft);
}

.GalleryMenu {
z-index: 1;
}
Expand Down
3 changes: 3 additions & 0 deletions docs/translations/api-docs-base/menu-item/menu-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"componentDescription": "An unstyled menu item to be used within a Menu.",
"propDescriptions": {
"disabled": { "description": "If <code>true</code>, the menu item will be disabled." },
"disableFocusOnHover": {
"description": "If <code>true</code>, the menu item won&#39;t receive focus when the mouse moves over it."
},
"label": {
"description": "A text representation of the menu item&#39;s content. Used for keyboard text navigation matching."
},
Expand Down
6 changes: 5 additions & 1 deletion docs/translations/api-docs/use-menu-item/use-menu-item.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"hookDescription": "",
"parametersDescriptions": {},
"parametersDescriptions": {
"disableFocusOnHover": {
"description": "If <code>true</code>, the menu item won&#39;t receive focus when the mouse moves over it."
}
},
"returnValueDescriptions": {
"disabled": { "description": "If <code>true</code>, the component is disabled." },
"focusVisible": {
Expand Down
6 changes: 6 additions & 0 deletions packages/mui-base/src/MenuItem/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ MenuItem.propTypes /* remove-proptypes */ = {
* @default false
*/
disabled: PropTypes.bool,
/**
* If `true`, the menu item won't receive focus when the mouse moves over it.
*
* @default false
*/
disableFocusOnHover: PropTypes.bool,
/**
* A text representation of the menu item's content.
* Used for keyboard text navigation matching.
Expand Down
Loading

0 comments on commit 147db41

Please sign in to comment.