@@ -21,7 +21,7 @@ import {
2121 useMediaQuery ,
2222 Theme ,
2323 useForkRef ,
24- Box ,
24+ Typography ,
2525} from '@mui/material' ;
2626import { useTranslate , useBasename , useEvent } from 'ra-core' ;
2727import { useHotkeys } from 'react-hotkeys-hook' ;
@@ -133,7 +133,7 @@ export const MenuItemLink = forwardRef<any, MenuItemLinkProps>(
133133 const renderMenuItem = ( ) => {
134134 return (
135135 < StyledMenuItem
136- className = { clsx ( className , {
136+ className = { clsx ( className , MenuItemLinkClasses . root , {
137137 [ MenuItemLinkClasses . active ] : ! ! match ,
138138 } ) }
139139 // @ts -ignore
@@ -143,27 +143,24 @@ export const MenuItemLink = forwardRef<any, MenuItemLinkProps>(
143143 { ...rest }
144144 onClick = { handleMenuTap }
145145 >
146- < Box
147- sx = { {
148- flexGrow : 1 ,
149- display : 'flex' ,
150- alignItems : 'center' ,
151- } }
152- >
153- { leftIcon && (
154- < ListItemIcon className = { MenuItemLinkClasses . icon } >
155- { leftIcon }
156- </ ListItemIcon >
157- ) }
146+ { leftIcon && (
147+ < ListItemIcon className = { MenuItemLinkClasses . icon } >
148+ { leftIcon }
149+ </ ListItemIcon >
150+ ) }
151+ < Typography variant = "inherit" noWrap sx = { { flexGrow : 1 } } >
158152 { children
159153 ? children
160154 : typeof primaryText === 'string'
161- ? translate ( primaryText , { _ : primaryText } )
155+ ? translate ( primaryText , {
156+ _ : primaryText ,
157+ } )
162158 : primaryText }
163- </ Box >
159+ </ Typography >
164160 { keyboardShortcut
165161 ? keyboardShortcutRepresentation ?? (
166162 < KeyboardShortcut
163+ className = { MenuItemLinkClasses . shortcut }
167164 keyboardShortcut = { keyboardShortcut }
168165 />
169166 )
@@ -210,17 +207,34 @@ export type MenuItemLinkProps = Omit<
210207const PREFIX = 'RaMenuItemLink' ;
211208
212209export const MenuItemLinkClasses = {
210+ root : `${ PREFIX } -root` ,
213211 active : `${ PREFIX } -active` ,
214212 icon : `${ PREFIX } -icon` ,
213+ shortcut : `${ PREFIX } -shortcut` ,
215214} ;
216215
217216const StyledMenuItem = styled ( MenuItem , {
218217 name : PREFIX ,
219218 overridesResolver : ( props , styles ) => styles . root ,
220219} ) ( ( { theme } ) => ( {
221220 color : ( theme . vars || theme ) . palette . text . secondary ,
222- justifyContent : 'space-between' ,
223- gap : theme . spacing ( 1 ) ,
221+
222+ [ `& .${ MenuItemLinkClasses . icon } ` ] : {
223+ color : ( theme . vars || theme ) . palette . text . secondary ,
224+ } ,
225+
226+ [ `& .${ MenuItemLinkClasses . shortcut } ` ] : {
227+ color : ( theme . vars || theme ) . palette . text . secondary ,
228+ fontSize : theme . typography . body2 . fontSize ,
229+ opacity : 0 ,
230+ display : 'none' ,
231+ transition : 'opacity 0.3s' ,
232+ } ,
233+
234+ [ `&:hover .${ MenuItemLinkClasses . shortcut } ` ] : {
235+ opacity : 0.7 ,
236+ display : 'inline-flex' ,
237+ } ,
224238
225239 [ `&.${ MenuItemLinkClasses . active } ` ] : {
226240 color : ( theme . vars || theme ) . palette . text . primary ,
@@ -238,19 +252,19 @@ const LinkRef = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => (
238252
239253declare module '@mui/material/styles' {
240254 interface ComponentNameToClassKey {
241- RaMenuItemLink : 'root' | 'active' | 'icon' ;
255+ [ PREFIX ] : 'root' | 'active' | 'icon' | 'shortcut ';
242256 }
243257
244258 interface ComponentsPropsList {
245- RaMenuItemLink : Partial < MenuItemLinkProps > ;
259+ [ PREFIX ] : Partial < MenuItemLinkProps > ;
246260 }
247261
248262 interface Components {
249- RaMenuItemLink ?: {
250- defaultProps ?: ComponentsPropsList [ 'RaMenuItemLink' ] ;
263+ [ PREFIX ] ?: {
264+ defaultProps ?: ComponentsPropsList [ typeof PREFIX ] ;
251265 styleOverrides ?: ComponentsOverrides <
252266 Omit < Theme , 'components' >
253- > [ 'RaMenuItemLink' ] ;
267+ > [ typeof PREFIX ] ;
254268 } ;
255269 }
256270}
0 commit comments