aiellie

Search

Find a component, template or page

GitHub
Design

Menu

Base UI's menu with this registry's surface on it, plus an optional search box that filters the rows.

fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/menu"

shadcn needs the @aiellie registry in components.json first. npx aiellie add menu adds it on its first run, then installs the same way.

Menu is Base UI's menu with this registry's surface on it, plus an optional search box that filters the rows as you type. It is the base of every menu here: the model, branch, project and plugin selectors, the add, help and user menus. Rows can be plain items, links, checkboxes, radio groups and submenus.

Getting started

  1. Add a trigger and rows

    Base UI composes through render, so the trigger becomes whatever button you pass it.

    components/chat-options.tsx
    "use client"
    
    import { MoreHorizontalIcon } from "@hugeicons/core-free-icons"
    import { HugeiconsIcon } from "@hugeicons/react"
    
    import {
      Menu,
      MenuContent,
      MenuItem,
      MenuSeparator,
      MenuTrigger,
    } from "@/components/ui/menu"
    import { Button } from "@/components/ui/button"
    
    export function ChatOptions({ onRename, onDelete }: {
      onRename: () => void
      onDelete: () => void
    }) {
      return (
        <Menu>
          <MenuTrigger render={<Button variant="ghost" size="icon-sm" />}>
            <HugeiconsIcon aria-hidden icon={MoreHorizontalIcon} />
          </MenuTrigger>
          <MenuContent align="end">
            <MenuItem onClick={onRename}>Rename</MenuItem>
            <MenuSeparator />
            <MenuItem variant="destructive" onClick={onDelete}>
              Delete
            </MenuItem>
          </MenuContent>
        </Menu>
      )
    }
  2. Turn on the search

    showSearch adds a box at the top that filters the rows by their text. Groups whose rows all filter out go with them.

    <MenuContent showSearch searchPlaceholder="Search projects">{rows}</MenuContent>

Anatomy

<button data-slot="menu-trigger" data-popup-open />

<div data-slot="menu-content" data-variant="glass">
  <div data-slot="menu-search" /> {/* only with showSearch */}
  <div data-slot="menu-item" data-highlighted data-variant="destructive">
    <svg /> {children} <span data-slot="menu-shortcut" />
  </div>
  <a data-slot="menu-link-item" />
  <div data-slot="menu-group">
    <div data-slot="menu-group-label" />
  </div>
  <div data-slot="menu-radio-group">
    <div data-slot="menu-radio-item"><span data-slot="menu-radio-item-indicator" /></div>
  </div>
  <div data-slot="menu-checkbox-item"><span data-slot="menu-checkbox-item-indicator" /></div>
  <div data-slot="menu-separator" />
  <div data-slot="menu-sub-trigger" /> {/* opens a menu-sub-content beside it */}
  <div data-slot="menu-footer" /> {/* only with footer, never filtered */}
</div>

The popup is glass by default: a translucent background with a blur, a hairline border and a shadow, 14px from the trigger's corner. variant="solid" drops the blur for a popup over busy content. Rows are 12px text in muted-foreground that turn foreground on highlight; icons are 16px. It grows from the trigger and fades, and caps its height at the space available, scrolling inside.

The search box is a row of the panel, not a field inside it, and its rows scroll under it. It matches each row's text, so rows must be the menu's own parts: a row wrapped in a component of your own is kept whatever the query. footer rows are pinned under the list and never filtered; given a function, they get the query, for a row that acts on what was typed.

Examples

Search with an action for what was typed

The footer gets the query, so it can offer to add a label that doesn't exist yet.

Checkboxes and radio groups

Radio rows choose one of a group and checkbox rows switch something on. Both keep the menu open, so several can be set in one go.

Submenus, shortcuts and destructive rows

API reference

MenuContent

The popup, with its portal and positioner. Takes Base UI's Menu.Popup props.

PropTypeDefaultDescription
side"top" | "bottom" | "left" | "right""bottom"Which side of the trigger it opens on.
align"start" | "center" | "end""start"How it lines up with the trigger.
sideOffset / alignOffsetnumber6 / 0Distance from the trigger.
variant"glass" | "solid""glass"With or without the blur behind it.
showSearchbooleanfalseAdds a search box that filters the rows.
searchPlaceholderstring"Search"The search box's placeholder.
emptyMessagestring"No matches"Shown when the search matches nothing.
footerReactNode | (query: string) => ReactNodeRows pinned under the list, which the search never filters.

MenuItem

Base UI's Menu.Item.

PropTypeDefaultDescription
variant"default" | "destructive""default"Destructive rows are red, for deleting or leaving.
onClick() => voidRuns when the row is chosen.
closeOnClickbooleantrueWhether choosing it closes the menu.
disabledbooleanfalseDims the row and skips it.

Parts

ExportRendersNotes
MenuBase UI Menu.RootHolds the open state. open and onOpenChange control it.
MenuTriggerbuttonTakes render for the element it should be.
MenuLinkItemaA row that is a real link. Pass render={<Link href />} for a Next link.
MenuCheckboxItemdivchecked and onCheckedChange; a tick shows while checked.
MenuRadioGroup / MenuRadioItemdivvalue and onValueChange on the group, value on each row.
MenuGroup / MenuGroupLabeldivA labelled group of rows.
MenuSeparatordivA hairline between groups.
MenuShortcutspanKeys at the end of a row.
MenuSub / MenuSubTrigger / MenuSubContentdivA row that opens another menu beside it.
menuItemstringThe row's class string, for rows you build yourself.