Skip to content
Haze UI

Dropdown menu

Button that opens a short list of links, with group headings, leading icons, trailing hints, a destructive style and one level of submenus.

pnpm dlx shadcn@latest add @haze/dropdown-menu
Open preview in a new tab
Livesmall script

When to use

  • An account or workspace menu in a navbar
  • Three to eight secondary destinations behind one button
  • A "more" button at the end of a table row or card

When not to use

  • Choosing a form value; use select
  • Only two actions, which fit as visible buttons
  • Panels with inputs or rich content; use popover

Installation

Add the Haze registry to components.json once, then install Dropdown menu with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/dropdown-menu
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Unique on the page. Links the trigger to the menu and names the CSS anchor.
items*{ label: string; href?: string; hint?: string; destructive?: boolean; separatorBefore?: boolean; heading?: string; icon?: Component; items?: { label: string; href: string; hint?: string; destructive?: boolean; separatorBefore?: boolean; icon?: Component }[] }[]–Menu links in order. separatorBefore draws a divider above an item. heading shows a small label above it to start a group. icon is a component such as one from @lucide/astro, drawn before the label. An item with items (and no href) becomes a submenu trigger with a trailing chevron; one level of nesting.
labelstring"Options"Visible trigger text when the trigger slot is not used.
ariaLabelstring–Accessible name for an icon-only trigger.
variant"primary" | "secondary" | "outline" | "ghost""outline"Trigger button style.
size"sm" | "md" | "lg" | "icon""md"Trigger button size.
triggerClassstring–Extra classes on the trigger button.
align"start" | "end""start"Trigger edge the menu lines up with.
side"bottom" | "top""bottom"Preferred edge of the trigger, with native viewport collision fallback.
classstring–Menu panel classes.
trigger slotslot–Custom trigger content, such as a name and a chevron.
header / actions slotsslot–Optional identity header and trailing native action form.

Keyboard interactions

EnterSpace
Open or close the menu from the trigger
TabShiftTab
Move through the menu links
ArrowUpArrowDownHomeEnd
Open from the trigger or move focus between links
Letters
Focus a matching link by its visible label
ArrowRightEnterSpace
On a submenu item, open it and focus its first link
ArrowLeftEscape
In a submenu, close it and return focus to its item
Escape
Close the menu and return focus to the trigger

Accessibility

  • This is a disclosure list of links, not an ARIA menu: items are reached with Tab, which needs no script and matches what links do.
  • Icons are aria-hidden and a heading is plain text above its link, so every link keeps its own name.
  • The menu scales and fades in over 150 ms and out again through the native popover; reduced-motion users get no animation.
  • The destructive style only adds color, so the item text itself must say what happens ("Sign out", "Delete project").
  • Opening and dismissal work natively. Enhancement adds arrow navigation, typeahead and a moving pointer highlight.
  • A submenu trigger is a button with aria-haspopup="menu" and aria-expanded; its panel gets role=menu and its links role=menuitem. The root list stays a disclosure of links, so the submenu is the one menu-pattern part.
  • Without scripting the submenu has no trigger: its links list inline under the submenu label, so every link stays reachable.
  • A submenu opens on hover after a 100 ms intent delay and closes 200 ms after the pointer leaves the row and the panel, so a diagonal path into the panel keeps it open. It enters with a 4 px slide and fade over 150 ms; reduced-motion users get none.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Dropdown menu" with `npx shadcn@latest add @haze/dropdown-menu`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import DropdownMenu from "@/components/haze/ui/dropdown-menu.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/dropdown-menu.md

  • Customize with real content

    Adapt the Haze dropdown-menu ui for our product. Replace the demo values of these props with our real content: id, items, label, ariaLabel, variant, size, triggerClass, align, side, class, trigger slot, header / actions slots. Keep the layout, the heading level rules and these accessibility details: This is a disclosure list of links, not an ARIA menu: items are reached with Tab, which needs no script and matches what links do. Icons are aria-hidden and a heading is plain text above its link, so every link keeps its own name. The menu scales and fades in over 150 ms and out again through the native popover; reduced-motion users get no animation. The destructive style only adds color, so the item text itself must say what happens ("Sign out", "Delete project"). Opening and dismissal work natively. Enhancement adds arrow navigation, typeahead and a moving pointer highlight. A submenu trigger is a button with aria-haspopup="menu" and aria-expanded; its panel gets role=menu and its links role=menuitem. The root list stays a disclosure of links, so the submenu is the one menu-pattern part. Without scripting the submenu has no trigger: its links list inline under the submenu label, so every link stays reachable. A submenu opens on hover after a 100 ms intent delay and closes 200 ms after the pointer leaves the row and the panel, so a diagonal path into the panel keeps it open. It enters with a 4 px slide and fade over 150 ms; reduced-motion users get none. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using dropdown-menu, check it fits: use it when an account or workspace menu in a navbar; three to eight secondary destinations behind one button; a "more" button at the end of a table row or card. Avoid it when choosing a form value; use select; only two actions, which fit as visible buttons; panels with inputs or rich content; use popover. Alternatives: @haze/popover, @haze/button.

Dependencies

  • npm: @lucide/astro
  • @haze/button
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog