Skip to main content

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​

PropTypeDefaultMeaning
at *MenuPosition–
children *ReactNode–`MenuItem`s and `MenuSeparator`s.
label *string–The menu's accessible name, e.g. "Actions for Script.pdf".
onClose *() => void–
PropTypeDefaultMeaning
onSelect *() => void–
dangerboolean–For deleting and leaving: red.
disabledboolean–
iconenum–
shortcutstring–A shortcut shown at the end.

Accessibility​

  • role="menu" with menuitems; 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.