Menu
import { Menu, MenuItem, MenuSeparator, menuPositionFrom } from "@study/ui"
Result
Loading...
Live Editor
function Example() { const [at, setAt] = useState(null); return ( <> <IconButton icon="more" label="Actions for Script.pdf" variant="secondary" onClick={(e) => setAt(menuPositionFrom(e.currentTarget))} /> {at && ( <Menu at={at} label="Actions for Script.pdf" onClose={() => setAt(null)}> <MenuItem icon="edit" onSelect={() => setAt(null)}>Rename</MenuItem> <MenuItem icon="folder" onSelect={() => setAt(null)}>Move</MenuItem> <MenuItem icon="download" onSelect={() => setAt(null)}>Download</MenuItem> <MenuSeparator /> <MenuItem icon="trash" danger onSelect={() => setAt(null)}>Move to trash</MenuItem> </Menu> )} </> ); }
On right-click too: setAt({ x: event.clientX, y: event.clientY }).
When to use
- For actions people rarely need: behind ⋯ on cards and rows, on right-click on files.
- At most seven entries; dangerous ones last, after a separator, with
danger. - Deleting from the menu asks first – with a ConfirmDialog – or goes to the trash.
Props
| Prop | Type | Default | Meaning |
|---|---|---|---|
at * | MenuPosition | – | |
children * | ReactNode | – | `MenuItem`s and `MenuSeparator`s. |
label * | string | – | The menu's accessible name, e.g. "Actions for Script.pdf". |
onClose * | () => void | – |
| Prop | Type | Default | Meaning |
|---|---|---|---|
onSelect * | () => void | – | |
danger | boolean | – | For deleting and leaving: red. |
disabled | boolean | – | |
icon | enum | – | |
shortcut | string | – | A shortcut shown at the end. |
Accessibility
role="menu"withmenuitems; the first one gets the focus.- Arrow keys, Home and End move; Escape closes and gives the focus back to the button.
- The menu stays inside the window and grows from the corner where it was opened.