nook
Browse the docs

Components

Dropdown Menu

Built on Base UI

A menu of actions opened from a button, with checkbox and radio items.

See the prompt

Installation

npx nook-ui@latest add dropdown-menu

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Dropdown Menu" component to this project, exactly as Nook ships it.

A menu of actions opened from a button, with checkbox and radio items.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add dropdown-menu`. It writes `components/ui/dropdown-menu.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/dropdown-menu.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
"use client";

import * as React from "react";
import { Button } from "@/components/ui/button";
import {
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";

export default function DropdownMenuDefault() {
  const [showTips, setShowTips] = React.useState(true);
  const [sort, setSort] = React.useState("newest");
  return (
    <DropdownMenu>
      <DropdownMenuTrigger render={<Button variant="outline" />}>Options</DropdownMenuTrigger>
      <DropdownMenuContent>
        <DropdownMenuGroup>
          <DropdownMenuLabel>My account</DropdownMenuLabel>
          <DropdownMenuItem>Profile</DropdownMenuItem>
          <DropdownMenuItem>Billing</DropdownMenuItem>
        </DropdownMenuGroup>
        <DropdownMenuSeparator />
        <DropdownMenuCheckboxItem checked={showTips} onCheckedChange={setShowTips}>
          Show tips
        </DropdownMenuCheckboxItem>
        <DropdownMenuSeparator />
        <DropdownMenuRadioGroup value={sort} onValueChange={setSort}>
          <DropdownMenuRadioItem value="newest">Newest first</DropdownMenuRadioItem>
          <DropdownMenuRadioItem value="oldest">Oldest first</DropdownMenuRadioItem>
        </DropdownMenuRadioGroup>
        <DropdownMenuSeparator />
        <DropdownMenuItem destructive>Sign out</DropdownMenuItem>
      </DropdownMenuContent>
    </DropdownMenu>
  );
}
```

API
- `DropdownMenu`: Owns the open state.
  - `open` (`boolean`): Controlled open state.
  - `onOpenChange` (`(open: boolean) => void`): Called when it opens or closes.
- `DropdownMenuTrigger`: The button that opens the menu. Use `render={<Button />}`.
- `DropdownMenuContent`: The popup.
  - `side` (`"top" | "right" | "bottom" | "left"`, default "bottom"): Preferred side.
  - `align` (`"start" | "center" | "end"`, default "start"): Alignment against the trigger.
  - `sideOffset` (`number`, default 6): Gap in pixels.
- `DropdownMenuItem`: An action.
  - `onClick` (`MouseEventHandler`): Runs when chosen.
  - `destructive` (`boolean`, default false): Marks the action as destructive without relying on color alone.
  - `closeOnClick` (`boolean`, default true): Close the menu after choosing.
  - `disabled` (`boolean`, default false): Disables the item.
- `DropdownMenuCheckboxItem`: A toggleable item.
  - `checked` (`boolean`): Controlled state.
  - `onCheckedChange` (`(checked: boolean) => void`): Called when toggled.
- `DropdownMenuRadioGroup / DropdownMenuRadioItem`: Pick one item from a set.
  - `value` (`string`): Selected value (group).
  - `onValueChange` (`(value: string) => void`): Called on change (group).
- `DropdownMenuGroup / DropdownMenuLabel / DropdownMenuSeparator`: Structure the menu.
- `DropdownMenuSub / DropdownMenuSubTrigger / DropdownMenuSubContent`: A nested menu. The trigger is an item with a chevron; the content opens to the right.
- `DropdownMenuShortcut`: Keys shown at the end of an item, for example ⌘K. Display only.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Arrow keys move, Enter or Space activates, typeahead jumps, Escape closes and returns focus to the trigger.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

"use client";

import * as React from "react";
import { Button } from "@/components/ui/button";
import {
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";

export default function DropdownMenuDefault() {
  const [showTips, setShowTips] = React.useState(true);
  const [sort, setSort] = React.useState("newest");
  return (
    <DropdownMenu>
      <DropdownMenuTrigger render={<Button variant="outline" />}>Options</DropdownMenuTrigger>
      <DropdownMenuContent>
        <DropdownMenuGroup>
          <DropdownMenuLabel>My account</DropdownMenuLabel>
          <DropdownMenuItem>Profile</DropdownMenuItem>
          <DropdownMenuItem>Billing</DropdownMenuItem>
        </DropdownMenuGroup>
        <DropdownMenuSeparator />
        <DropdownMenuCheckboxItem checked={showTips} onCheckedChange={setShowTips}>
          Show tips
        </DropdownMenuCheckboxItem>
        <DropdownMenuSeparator />
        <DropdownMenuRadioGroup value={sort} onValueChange={setSort}>
          <DropdownMenuRadioItem value="newest">Newest first</DropdownMenuRadioItem>
          <DropdownMenuRadioItem value="oldest">Oldest first</DropdownMenuRadioItem>
        </DropdownMenuRadioGroup>
        <DropdownMenuSeparator />
        <DropdownMenuItem destructive>Sign out</DropdownMenuItem>
      </DropdownMenuContent>
    </DropdownMenu>
  );
}

Examples

Profile menu

Press the name to open the account menu.

Submenu and shortcuts

Icons and shortcuts

Disabled items

Alignment

Row actions

  • Ana Souza · Owner
  • Kofi Mensah · Admin
  • Priya Nair · Editor

Props

DropdownMenu

Owns the open state.

PropTypeDefaultDescription
openboolean–Controlled open state.
onOpenChange(open: boolean) => void–Called when it opens or closes.

DropdownMenuTrigger

The button that opens the menu. Use `render={<Button />}`.

DropdownMenuContent

The popup.

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""bottom"Preferred side.
align"start" | "center" | "end""start"Alignment against the trigger.
sideOffsetnumber6Gap in pixels.

DropdownMenuItem

An action.

PropTypeDefaultDescription
onClickMouseEventHandler–Runs when chosen.
destructivebooleanfalseMarks the action as destructive without relying on color alone.
closeOnClickbooleantrueClose the menu after choosing.
disabledbooleanfalseDisables the item.

DropdownMenuCheckboxItem

A toggleable item.

PropTypeDefaultDescription
checkedboolean–Controlled state.
onCheckedChange(checked: boolean) => void–Called when toggled.

DropdownMenuRadioGroup / DropdownMenuRadioItem

Pick one item from a set.

PropTypeDefaultDescription
valuestring–Selected value (group).
onValueChange(value: string) => void–Called on change (group).

DropdownMenuGroup / DropdownMenuLabel / DropdownMenuSeparator

Structure the menu.

DropdownMenuSub / DropdownMenuSubTrigger / DropdownMenuSubContent

A nested menu. The trigger is an item with a chevron; the content opens to the right.

DropdownMenuShortcut

Keys shown at the end of an item, for example ⌘K. Display only.

Accessibility

Arrow keys move, Enter or Space activates, typeahead jumps, Escape closes and returns focus to the trigger.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.