> ## Documentation Index
> Fetch the complete documentation index at: https://npm-packages.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Menu

> Change list density and metadata from a menu with a nested sort selector.

Package: [`@base-ui/react`](https://www.npmjs.com/package/@base-ui/react).

## Try it

Open **View options**. Toggle compact spacing and category labels, then choose **Sort by → Oldest first** to reverse the list.

## Code

```tsx base-ui-menu.tsx theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { Menu } from "@base-ui/react/menu";
import { useState } from "react";

import { DemoIcon } from "./demo-icons.tsx";
import "./base-ui-example.css";

const files = [
  { title: "quickstart.mdx", date: "October 14", category: "Guide" },
  { title: "authentication.mdx", date: "October 10", category: "Reference" },
  { title: "changelog.mdx", date: "October 7", category: "Updates" },
];

export function BaseUiMenu() {
  const [compact, setCompact] = useState(false);
  const [showCategory, setShowCategory] = useState(true);
  const [sort, setSort] = useState("newest");
  const visibleFiles = sort === "newest" ? files : [...files].reverse();

  return (
    <div className="base-ui-example">
      <div className="base-ui-demo-heading">
        <strong>Documentation</strong>
        <Menu.Root>
          <Menu.Trigger className="demo-button">
            View options <DemoIcon name="chevron-down" />
          </Menu.Trigger>
          <Menu.Portal>
            <Menu.Positioner className="base-ui-positioner" sideOffset={6} align="end">
              <Menu.Popup className="base-ui-popup base-ui-menu-popup">
                <Menu.Group>
                  <Menu.GroupLabel className="base-ui-menu-label">Display</Menu.GroupLabel>
                  <Menu.CheckboxItem
                    className="base-ui-option"
                    checked={compact}
                    onCheckedChange={setCompact}
                  >
                    <Menu.CheckboxItemIndicator className="base-ui-item-indicator">
                      <DemoIcon name="check" />
                    </Menu.CheckboxItemIndicator>
                    Compact spacing
                  </Menu.CheckboxItem>
                  <Menu.CheckboxItem
                    className="base-ui-option"
                    checked={showCategory}
                    onCheckedChange={setShowCategory}
                  >
                    <Menu.CheckboxItemIndicator className="base-ui-item-indicator">
                      <DemoIcon name="check" />
                    </Menu.CheckboxItemIndicator>
                    Show category
                  </Menu.CheckboxItem>
                </Menu.Group>
                <Menu.Separator className="base-ui-menu-separator" />
                <Menu.SubmenuRoot>
                  <Menu.SubmenuTrigger className="base-ui-option base-ui-submenu-trigger">
                    Sort by <DemoIcon name="chevron-right" />
                  </Menu.SubmenuTrigger>
                  <Menu.Portal>
                    <Menu.Positioner className="base-ui-positioner" sideOffset={4} alignOffset={-4}>
                      <Menu.Popup className="base-ui-popup base-ui-menu-popup">
                        <Menu.RadioGroup value={sort} onValueChange={setSort}>
                          <Menu.RadioItem className="base-ui-option" value="newest">
                            <Menu.RadioItemIndicator className="base-ui-item-indicator">
                              <DemoIcon name="check" />
                            </Menu.RadioItemIndicator>
                            Newest first
                          </Menu.RadioItem>
                          <Menu.RadioItem className="base-ui-option" value="oldest">
                            <Menu.RadioItemIndicator className="base-ui-item-indicator">
                              <DemoIcon name="check" />
                            </Menu.RadioItemIndicator>
                            Oldest first
                          </Menu.RadioItem>
                        </Menu.RadioGroup>
                      </Menu.Popup>
                    </Menu.Positioner>
                  </Menu.Portal>
                </Menu.SubmenuRoot>
              </Menu.Popup>
            </Menu.Positioner>
          </Menu.Portal>
        </Menu.Root>
      </div>
      <div className="base-ui-reading-list" data-compact={compact}>
        {visibleFiles.map((file) => (
          <div className="base-ui-reading-row" key={file.title}>
            <div>
              <strong>{file.title}</strong>
              {showCategory && <span>{file.category}</span>}
            </div>
            <time>{file.date}</time>
          </div>
        ))}
      </div>
      <p className="base-ui-helper" role="status">
        Sorted {sort} first. {compact ? "Compact" : "Comfortable"} spacing.
      </p>
    </div>
  );
}
```

## Keyboard

Open the menu with Enter or Arrow Down. Use the arrow keys to navigate and Arrow Right to enter the submenu. Escape closes the submenu first, then the parent menu.

## Key props

| Prop or part | Purpose |
| - | - |
| `Menu.CheckboxItem` | Toggle independent settings without closing the menu. |
| `Menu.RadioGroup` | Keep one sort order selected. |
| `Menu.SubmenuRoot` | Give related actions their own nested menu. |
| `Menu.Positioner` | Keep each popup aligned with its trigger and within the viewport. |

[Base UI Menu documentation](https://base-ui.com/react/components/menu)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.