Context Menu

The menu's popup, rows and submenus, opened at the pointer by a right-click or a long press.

01Preview

01
Full screen
Weekly planning notesRight-click, or long-press on touch

02Installation

npx shadcn@latest add https://aiellie.app/r/context-menu.json

03API reference

19
From the Base UI documentation

A component that creates a context menu activated by right clicking or long pressing. Doesn't render its own HTML element.

Props

PropTypeDefaultDescription
defaultOpenbooleanfalseWhether the menu is initially open. To render a controlled menu, use the open prop instead.
openboolean-Whether the menu is currently open.
onOpenChange((open: boolean, eventDetails: ContextMenu.Root.ChangeEventDetails) => void)-Event handler called when the menu is opened or closed.
highlightItemOnHoverbooleantrueWhether moving the pointer over items should highlight them. Disabling this prop allows CSS :hover to be differentiated from the :focus (data-highlighted) state.
actionsRefReact.RefObject<MenuRoot.Actions | null>-A ref to imperative actions. unmount: Manually unmounts the menu. Call this after any externally controlled closing animation finishes.close: When specified, the menu can be closed imperatively.
loopFocusbooleantrueWhether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.
onOpenChangeComplete((open: boolean) => void)-Event handler called after any animations complete when the menu is opened or closed.
disabledbooleanfalseWhether the component should ignore user interaction.
orientationMenuRoot.Orientation'vertical'The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys.
childrenReact.ReactNode--