Dropdown Menu
Dropdown Menu with thoughtful defaults, semantic styling, and editable source.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/dropdown-menu.jsonUse it
Scroll horizontally for long lines
"use client";
import {useState} from 'react';
import {DropdownMenu} from '@/components/jez-ui/ui/dropdown-menu';
import {Button} from '@/components/jez-ui/ui/button';
export default function Example(){
const [notice,setNotice]=useState('');
const actions=[{label:'Duplicate',onSelect:()=>setNotice('A copy is ready.')},{label:'Archive',onSelect:()=>setNotice('Moved to archive.')}];
return <><DropdownMenu trigger={<Button variant="outline">Project actions ↓</Button>} items={actions}/><p role="status">{notice}</p></>;
}Props & types
Scroll horizontally for long lines
{
trigger: React.ReactNode;
items: { label: string; onSelect: () => void; disabled?: boolean }[];
className?: string;
}Source
View 2 source files
registry/ui/dropdown-menu.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import { DropdownMenu as Primitive } from "radix-ui";
export function DropdownMenu({
trigger,
items,
className,
}: {
trigger: React.ReactNode;
items: { label: string; onSelect: () => void; disabled?: boolean }[];
className?: string;
}) {
return (
<Primitive.Root>
<Primitive.Trigger asChild>{trigger}</Primitive.Trigger>
<Primitive.Portal>
<Primitive.Content
className={cn(
"z-50 min-w-44 rounded-xl border border-border bg-background p-1 text-foreground shadow-lg",
className,
)}
>
{items.map((i, n) => (
<Primitive.Item
key={n}
disabled={i.disabled}
onSelect={i.onSelect}
className="cursor-pointer rounded-lg px-3 py-2 text-sm outline-none data-[highlighted]:bg-muted data-[disabled]:opacity-40"
>
{i.label}
</Primitive.Item>
))}
</Primitive.Content>
</Primitive.Portal>
</Primitive.Root>
);
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
Dependencies
radix-ui@1.6.7 · clsx@2.1.1 · tailwind-merge@3.5.0
Accessibility & behaviour
Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.
Read the accessibility and performance guide →