Context menu components

FREE

Free and open-source React context menu components built for modern applications and websites. Trigger these menus with a right-click, long-press, or the keyboard menu key, built using React Aria and styled with Tailwind CSS.

Installation

Context menus reuse the same Dropdown component as our dropdown menus — only the trigger changes. You can add it using our CLI or manually:

npx untitledui@latest add dropdown

Context menu examples

Below are examples and variations of this context menu component. Right-click (or long-press on touch) the highlighted area to open the menu.

API reference

Import the parts and assemble them:

import { Dropdown } from "@/components/base/dropdown/dropdown";
 
<Dropdown.Popover>
    <Dropdown.Menu>
        <Dropdown.Item />
        <Dropdown.Item />
        <Dropdown.Separator />
        <Dropdown.Item />
    </Dropdown.Menu>
</Dropdown.Popover>

FAQs

Please refer to our frequently asked questions page for more.

Set the trigger prop to "contextMenu" on Dropdown.Root. The first child becomes the target area that opens the menu on right-click (or long-press on touch devices), and the menu opens at the pointer position instead of anchored to a button.

The target must be a React Aria pressable element, so wrap your content in an AriaButton (or Pressable) from react-aria-components. React Aria attaches the right-click and long-press handlers to it and manages focus and keyboard access for you.

With the target focused, press Shift+F10 on Windows and Linux or Control+Enter on macOS. Enter and Space do not open a context menu. Once it is open, the arrow keys move between items, Enter selects, and Escape closes the menu.

Yes. Wrap a Dropdown.Item and a nested Dropdown.Popover in a SubmenuTrigger from react-aria-components, exactly as you would in a regular dropdown. See the advanced example above for nested submenus.

Set selectionMode="multiple" (or "single") on a Dropdown.Section and control it with selectedKeys and onSelectionChange, as the advanced example does. Selected items show a checkmark by default; set selectionIndicator on Dropdown.Item to "checkbox", "radio", "toggle" or "none" to change it. Pass the addon prop on a Dropdown.Item to show a shortcut such as ⌘C.

Context menus reuse the Dropdown component, so install it with npx untitledui@latest add dropdown. The examples import Dropdown from @/components/base/dropdown/dropdown, plus Button (as AriaButton) and SubmenuTrigger from react-aria-components.