Skip to content

Commit

Permalink
[Doc] Fix <AppBar userMenu> example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Nov 18, 2024
1 parent 60d2de9 commit f333b14
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions docs/AppBar.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,26 @@ 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 `<AppBar>` component.

```jsx
```tsx
import * as React from 'react';
import { AppBar, UserMenu, useUserMenu } from 'react-admin';
import { AppBar, Logout, UserMenu, useUserMenu } from 'react-admin';
import { MenuItem, ListItemIcon, ListItemText } from '@mui/material';
import SettingsIcon from '@mui/icons-material/Settings';
import { Link } from "react-router-dom";

// It's important to pass the ref to allow Material UI 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();
const SettingsMenuItem = React.forwardRef<HTMLAnchorElement>((props, ref) => {
const userMenuContext = useUserMenu();
if (!userMenuContext) {
throw new Error("<SettingsMenuItem> should be used inside a <UserMenu>");
}
const { onClose } = userMenuContext;
return (
<MenuItem
onClick={onClose}
ref={ref}
component={Link}
to="/settings"
// It's important to pass the props to allow Material UI to manage the keyboard navigation
{...props}
>
Expand All @@ -273,10 +279,10 @@ const SettingsMenuItem = React.forwardRef((props, ref) => {
);
});

const MyAppBar = () => (
export const MyAppBar = () => (
<AppBar
userMenu={
<UserMenu>
<UserMenu>
<SettingsMenuItem />
<Logout />
</UserMenu>
Expand Down

0 comments on commit f333b14

Please sign in to comment.