Skip to content
Page

Menu

Menu with labels, shortcuts, descriptions, and submenus.

import {
Menu,
MenuTrigger,
MenuPopover,
MenuList,
MenuItem,
MenuLabel,
MenuDivider,
} from "@pelagornis/page/components";

The preview above renders this file. Copy it into src/components/ to start from it.

src/components/MenuExample.tsx
import {
Button,
Menu,
MenuDivider,
MenuItem,
MenuLabel,
MenuList,
MenuPopover,
MenuTrigger,
} from "@pelagornis/page/components";
export default function MenuDemo() {
return (
<Menu>
<MenuTrigger>
<Button variant="outline">File</Button>
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuLabel>File</MenuLabel>
<MenuItem shortcut="⌘N">New file</MenuItem>
<MenuItem shortcut="⌘O" description="Open from disk">
Open
</MenuItem>
<MenuDivider />
<MenuItem state="disabled">Save</MenuItem>
</MenuList>
</MenuPopover>
</Menu>
);
}

Menu is composed from parts that share React state. Children written in MDX are rendered as separate islands, so the parts can’t reach each other. Put the composition in a .tsx file, like the example above, and import that file instead.

src/content/docs/example.mdx
---
title: Example
---
import MenuExample from "../../components/MenuExample";
<MenuExample client:load />

client:load hydrates the island on page load. Use client:visible for content far down the page.

Markdoc tags render Astro components, and this one needs client state. Wrap the example in an .astro file that hydrates it, then register that file as a tag.

src/components/markdoc/MenuExample.astro
---
import MenuExample from "../MenuExample";
---
<MenuExample client:load />
markdoc.config.mjs
import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";
import starlightMarkdoc from "@astrojs/starlight-markdoc";
import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({
extends: [starlightMarkdoc(), pageMarkdoc()],
tags: {
"menu-example": {
render: component("./src/components/markdoc/MenuExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% menu-example /%}

Parts of the component and the data-refineui role each one renders.

PartRole
rootmenu-root
dividermenu-divider
itemmenu-item
popovermenu-popover
labelmenu-label

States the component styles. Component states are exposed as data attributes.

KindStates
Pseudofocus-visible
data-stateopen closed default hover pressed active disabled

Keys the component handles when it has focus.

KeyAction
Escapeclose
Enteractivate
Spaceactivate