Back to Dropdowns
Components / Dropdowns
Kebab Actions
Free Dropdowns React component — KebabActionsDropdown. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.
List row that expands inline — actions open inside the same card so widths always align.
Preview
Quarterly report
Setup
How to use
Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.
- 1
Run in your terminal:
$npm install clsx tailwind-merge lucide-react - 2
Copy
lib/cn.tsbelow. Skip if you already havecn(). - 3
Copy the code below and create
components/dropdowns/kebab-actions-dropdown.tsxin your project. - 4
Import and render:
Exampleimport { KebabActionsDropdown } from "@/components/dropdowns/kebab-actions-dropdown";
lib/cn.ts
import { type ClassValue, clsx } from "clsx";import { twMerge } from "tailwind-merge";export function cn(...inputs: ClassValue[]) {return twMerge(clsx(inputs));}
components/dropdowns/kebab-actions-dropdown.tsx
"use client";import {forwardRef,useEffect,useId,useRef,useState,type ComponentPropsWithoutRef,type ComponentType,} from "react";import { cn } from "@/lib/cn";import { MoreVertical, Pencil, Link, Archive, Trash } from "lucide-react";type IconComponent = ComponentType<Readonly<{ size?: number; className?: string }>>;export type KebabMenuItem = Readonly<{id: string;label?: string;icon?: IconComponent;danger?: boolean;separator?: boolean;}>;export type KebabActionsDropdownProps = Readonly<{rowTitle?: string;triggerAriaLabel?: string;menuAriaLabel?: string;items?: readonly KebabMenuItem[];onItemClick?: (item: KebabMenuItem) => void;} & ComponentPropsWithoutRef<"div">>;const defaultItems: readonly KebabMenuItem[] = [{ id: "edit", label: "Edit", icon: Pencil },{ id: "copy-link", label: "Copy link", icon: Link },{ id: "archive", label: "Archive", icon: Archive },{ id: "separator-delete", separator: true },{ id: "delete", label: "Delete", icon: Trash, danger: true },];type KebabMenuItemRowProps = Readonly<{item: KebabMenuItem;onSelect: (item: KebabMenuItem) => void;}>;function KebabMenuItemRow({ item, onSelect }: KebabMenuItemRowProps) {if (item.separator) {return <hr className="border-0 border-t border-neutral-100" />;}const Icon = item.icon;return (<buttontype="button"role="menuitem"aria-label={item.label}onClick={() => onSelect(item)}className={cn("flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-[12px] font-medium transition-colors",item.danger? "text-red-500 hover:bg-red-50": "text-neutral-700 hover:bg-neutral-50",)}>{Icon ? (<Iconsize={12}className={item.danger ? "text-red-400" : "text-neutral-400"}/>) : null}{item.label}</button>);}// Inline expand row — menu opens inside the same card, widths always match.export const KebabActionsDropdown = forwardRef<HTMLDivElement,KebabActionsDropdownProps>(({rowTitle = "Quarterly report",triggerAriaLabel = "More actions",menuAriaLabel = "Actions menu",items = defaultItems,onItemClick,className,...props},ref,) => {const [open, setOpen] = useState(false);const rootRef = useRef<HTMLDivElement>(null);const menuId = useId();useEffect(() => {const closeOnOutside = (event: globalThis.MouseEvent) => {if (!rootRef.current?.contains(event.target as Node)) {setOpen(false);}};const closeOnEscape = (event: KeyboardEvent) => {if (event.key === "Escape") setOpen(false);};document.addEventListener("mousedown", closeOnOutside);document.addEventListener("keydown", closeOnEscape);return () => {document.removeEventListener("mousedown", closeOnOutside);document.removeEventListener("keydown", closeOnEscape);};}, []);const handleItemSelect = (item: KebabMenuItem) => {setOpen(false);onItemClick?.(item);};const toggleOpen = () => setOpen((prev) => !prev);return (<divref={ref}data-slot="kebab-actions-dropdown"className={cn("relative inline-block font-sans", className)}{...props}><divref={rootRef}className={cn("w-56 overflow-hidden rounded-xl border border-neutral-100 bg-white",open && "shadow-[0_20px_50px_-12px_rgba(0,0,0,0.05)]",)}><div className="flex items-center gap-2 py-2 pr-2 pl-3"><span className="min-w-0 flex-1 truncate text-[12px] font-medium text-neutral-700">{rowTitle}</span><buttontype="button"aria-label={triggerAriaLabel}aria-expanded={open}aria-haspopup="menu"aria-controls={open ? menuId : undefined}onClick={toggleOpen}onKeyDown={(event) => {if (event.key === "Enter" || event.key === " ") {event.preventDefault();toggleOpen();}}}className={cn("inline-flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-lg transition-colors",open? "bg-neutral-100 text-neutral-700": "text-neutral-400 hover:bg-neutral-50 hover:text-neutral-600",)}><MoreVertical size={15} strokeWidth={2} /></button></div>{open ? (<divid={menuId}role="menu"aria-label={menuAriaLabel}className="border-t border-neutral-100 py-1">{items.map((item) => (<KebabMenuItemRowkey={item.id}item={item}onSelect={handleItemSelect}/>))}</div>) : null}</div></div>);},);KebabActionsDropdown.displayName = "KebabActionsDropdown";