Dropdown
A keyboard-accessible menu of actions.
Give your AI assistant this page as context.
Connect your library with MCPui/dropdownUsage
Get this component from a saved library export or the connected CLI. The imports below refer to local files installed in your app.
Import styles/components.css, then styles/theme.css once. Wrap your app in ThemeScope from components/ui/utils so typography, focus and overlays share the theme. The installation guide covers runtime dependencies and React/Next.js setup.
import { Dropdown } from './components/ui/dropdown';
<Dropdown trigger="Project actions" items={[{label:"Rename",onSelect:()=>console.info("Rename")},{label:"Archive",onSelect:()=>console.info("Archive")} ]}/>Design system
This component consumes your semantic colors, spacing, typography and shape tokens. Import the compiled styles and your theme once as described in Export.
Behavior and accessibility
- Provide meaningful labels for interactive controls.
- Connect action callbacks to your application logic.
- Verify keyboard navigation and contrast in your application.
Status: experimental during early access. Sample previews do not send emails, process payments or upload files to a service.
Source and props
This is the exported source, using the same implementation as the editor.
"use client";
import { Menu as Base } from "@base-ui/react/menu";
import type { ComponentProps, ReactNode } from "react";
import { usePortalContainer } from "./utils";
export interface MenuAction {
id?: string;
label: string;
onSelect?: () => void;
href?: string;
disabled?: boolean;
destructive?: boolean;
}
export function Dropdown({
trigger,
triggerRender,
items,
disabled = false,
side = "bottom",
align = "start",
emptyMessage = "No actions available.",
...rootProps
}: Omit<ComponentProps<typeof Base.Root>, "children"> & {
trigger?: ReactNode;
triggerRender?: ComponentProps<typeof Base.Trigger>["render"];
items: MenuAction[];
disabled?: boolean;
side?: ComponentProps<typeof Base.Positioner>["side"];
align?: ComponentProps<typeof Base.Positioner>["align"];
emptyMessage?: ReactNode;
}) {
const container = usePortalContainer();
return (
<Base.Root {...rootProps}>
<Base.Trigger
render={triggerRender}
disabled={disabled}
className="cr-button"
data-variant="outline"
>
{trigger}
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.75"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<path d="m6 9 6 6 6-6" />
</svg>
</Base.Trigger>
<Base.Portal container={container}>
<Base.Positioner
side={side}
align={align}
sideOffset={6}
className="cr-positioner"
>
<Base.Popup className="cr-popup">
{!items.length && <p className="cr-description">{emptyMessage}</p>}
{items.map((item, index) => (
<Base.Item
key={item.id ?? index}
render={
item.href && !item.disabled ? (
<a href={item.href}>{item.label}</a>
) : undefined
}
className="cr-menu-item"
data-destructive={item.destructive || undefined}
disabled={item.disabled}
onClick={item.onSelect}
>
{item.label}
</Base.Item>
))}
</Base.Popup>
</Base.Positioner>
</Base.Portal>
</Base.Root>
);
}