Skip to content

Commit

Permalink
Merge pull request #10356 from marmelab/doc-appbar-usermenu
Browse files Browse the repository at this point in the history
[Doc] Fix `<AppBar userMenu>` example usage
  • Loading branch information
djhi authored Nov 18, 2024
2 parents a733c6c + 7c88d4e commit 75f547f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 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,7 +279,7 @@ const SettingsMenuItem = React.forwardRef((props, ref) => {
);
});

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

0 comments on commit 75f547f

Please sign in to comment.