diff --git a/docs/AppBar.md b/docs/AppBar.md index 50d9dbafbe7..b5964385adf 100644 --- a/docs/AppBar.md +++ b/docs/AppBar.md @@ -238,21 +238,29 @@ The content of the user menu depends on the return value of `authProvider.getIde You can customize the user menu by passing a `userMenu` prop to the `` component. ```jsx +import * as React from 'react'; import { AppBar, UserMenu, useUserMenu } from 'react-admin'; import { MenuItem, ListItemIcon, ListItemText } from '@mui/material'; import SettingsIcon from '@mui/icons-material/Settings'; -const SettingsMenuItem = () => { +// It's important to pass the ref to allow MUI to manage the keyboard navigation +const SettingsMenuItem = React.forwardRef((props, ref) => { + // We are not using MenuItemLink so we retrieve the onClose function from the UserContext const { onClose } = useUserMenu(); return ( - + Customize ); -}; +}); const MyAppBar = () => ( { const logout = useLogout(); const handleClick = () => logout(); @@ -349,6 +350,8 @@ const MyLogoutButton = forwardRef((props, ref) => { Logout diff --git a/docs/ContainerLayout.md b/docs/ContainerLayout.md index 8795e05b843..934b669f24c 100644 --- a/docs/ContainerLayout.md +++ b/docs/ContainerLayout.md @@ -161,16 +161,19 @@ By default, the `` shows a user menu with a single item (logout {% raw %} ```jsx +import * as React from 'react'; import { Logout, UserMenu, useUserMenu } from 'react-admin'; import { MenuList, MenuItem, ListItemIcon, ListItemText } from '@mui/material'; import SettingsIcon from '@mui/icons-material/Settings'; import { ContainerLayout } from '@react-admin/ra-navigation'; +// It's important to pass the ref to allow MUI to manage the keyboard navigation const ConfigurationMenu = React.forwardRef((props, ref) => { const { onClose } = useUserMenu(); return ( { }); // It's important to pass the ref to allow MUI to manage the keyboard navigation -const SwitchLanguage = forwardRef((props, ref) => { +const SwitchLanguage = React.forwardRef((props, ref) => { const [locale, setLocale] = useLocaleState(); // We are not using MenuItemLink so we retrieve the onClose function from the UserContext const { onClose } = useUserMenu(); diff --git a/docs/useLogout.md b/docs/useLogout.md index 481a6427309..31aca550f4c 100644 --- a/docs/useLogout.md +++ b/docs/useLogout.md @@ -15,6 +15,7 @@ import { AppBar, Layout, UserMenu, useLogout } from 'react-admin'; import { MenuItem } from '@mui/material'; import ExitIcon from '@mui/icons-material/PowerSettingsNew'; +// It's important to pass the ref to allow MUI to manage the keyboard navigation const MyLogoutButton = forwardRef((props, ref) => { const logout = useLogout(); const handleClick = () => logout(); @@ -22,6 +23,8 @@ const MyLogoutButton = forwardRef((props, ref) => { Logout diff --git a/packages/ra-ui-materialui/src/layout/AppBar.stories.tsx b/packages/ra-ui-materialui/src/layout/AppBar.stories.tsx index ddb4d5fb63c..cf049a3fc1b 100644 --- a/packages/ra-ui-materialui/src/layout/AppBar.stories.tsx +++ b/packages/ra-ui-materialui/src/layout/AppBar.stories.tsx @@ -8,6 +8,7 @@ import { ListItemText, TextField, Skeleton, + MenuItemProps, } from '@mui/material'; import SettingsIcon from '@mui/icons-material/Settings'; import { QueryClientProvider, QueryClient } from 'react-query'; @@ -197,17 +198,26 @@ export const UserMenuCustom = () => ( ); -const SettingsMenuItem = () => { - const { onClose } = useUserMenu(); - return ( - - - - - Customize - - ); -}; +// It's important to pass the ref to allow MUI to manage the keyboard navigation +const SettingsMenuItem: React.FC = React.forwardRef( + (props, ref) => { + // We are not using MenuItemLink so we retrieve the onClose function from the UserContext + const { onClose } = useUserMenu(); + return ( + + + + + Customize + + ); + } +); export const UserMenuElements = () => (