- Accordion
- Attachment
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Card
- Checkbox
- Code Block
- Collapsible
- Dialog
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Label
- Marker
- Message
- Number Flow
- Pagination
- Popover
- Progress
- Radio Group
- Select
- Slider
- Sonner
- Spinner
- Switch
- Tooltip
- Separator
- Sheet
- Tabs
- Textarea
- Toggle
- Toggle Group
- Trace
Accordion
A vertically stacked set of interactive headings that each reveal a section of content.
"use client";
import { ChevronDownIcon } from "lucide-react";
import * as React from "react";
import { getTransition, parseMotion, useReducedMotion } from "@/lib/motion";
import { cn } from "@/lib/utils";
const defaultMotion = "450 cubic-bezier(0.32, 0.72, 0, 1)";
type AccordionType = "single" | "multiple";
type AccordionOrientation = "horizontal" | "vertical";
interface AccordionContextValue {
collapsible: boolean;
disabled: boolean;
itemTriggerRefs: React.RefObject<(HTMLButtonElement | null)[]>;
motion: string | undefined;
onValueChange: (next: string[]) => void;
orientation: AccordionOrientation;
type: AccordionType;
value: string[];
}
const AccordionContext = React.createContext<AccordionContextValue | null>(
null
);
interface AccordionItemContextValue {
disabled: boolean;
itemId: string;
open: boolean;
value: string;
}
const AccordionItemContext =
React.createContext<AccordionItemContextValue | null>(null);
function normalizeValue(value: string | string[] | undefined): string[] {
if (value === undefined) {
return [];
}
if (Array.isArray(value)) {
return value;
}
return [value];
}
interface AccordionProps
extends Omit<React.ComponentProps<"div">, "defaultValue" | "onChange"> {
collapsible?: boolean;
defaultValue?: string | string[];
disabled?: boolean;
motion?: string;
onValueChange?: ((value: string) => void) | ((value: string[]) => void);
orientation?: AccordionOrientation;
type: AccordionType;
value?: string | string[];
}
function Accordion({
className,
children,
collapsible = false,
defaultValue,
disabled = false,
motion,
onValueChange,
orientation = "vertical",
type,
value: valueProp,
...props
}: AccordionProps) {
const [uncontrolledValue, setUncontrolledValue] = React.useState<string[]>(
() => normalizeValue(defaultValue)
);
const isControlled = valueProp !== undefined;
const value = isControlled ? normalizeValue(valueProp) : uncontrolledValue;
const itemTriggerRefs = React.useRef<(HTMLButtonElement | null)[]>([]);
const setValue = React.useCallback(
(next: string[]) => {
if (!isControlled) {
setUncontrolledValue(next);
}
if (onValueChange) {
if (type === "single") {
(onValueChange as (v: string) => void)(next[0] ?? "");
} else {
(onValueChange as (v: string[]) => void)(next);
}
}
},
[isControlled, onValueChange, type]
);
const ctx: AccordionContextValue = {
collapsible,
disabled,
itemTriggerRefs,
motion,
onValueChange: setValue,
orientation,
type,
value,
};
return (
<AccordionContext.Provider value={ctx}>
<div
className={className}
data-orientation={orientation}
data-slot="accordion"
{...props}
>
{children}
</div>
</AccordionContext.Provider>
);
}
interface AccordionItemProps extends React.ComponentProps<"div"> {
disabled?: boolean;
value: string;
}
function AccordionItem({
className,
children,
disabled = false,
value,
...props
}: AccordionItemProps) {
const ctx = React.useContext(AccordionContext);
if (!ctx) {
throw new Error("AccordionItem must be used within Accordion");
}
const isDisabled = ctx.disabled || disabled;
const open = ctx.value.includes(value);
const itemId = React.useId();
return (
<AccordionItemContext.Provider
value={{ disabled: isDisabled, itemId, open, value }}
>
<div
className={cn("border-b last:border-b-0", className)}
data-disabled={isDisabled ? "" : undefined}
data-slot="accordion-item"
data-state={open ? "open" : "closed"}
{...props}
>
{children}
</div>
</AccordionItemContext.Provider>
);
}
function AccordionHeader({ className, ...props }: React.ComponentProps<"h3">) {
return (
<h3
className={cn("flex", className)}
data-slot="accordion-header"
{...props}
/>
);
}
interface AccordionTriggerProps extends React.ComponentProps<"button"> {}
function AccordionTrigger({
className,
children,
onClick,
onKeyDown,
ref,
...props
}: AccordionTriggerProps) {
const ctx = React.useContext(AccordionContext);
const item = React.useContext(AccordionItemContext);
if (!(ctx && item)) {
throw new Error("AccordionTrigger must be used within AccordionItem");
}
const internalRef = React.useRef<HTMLButtonElement>(null);
const setRef = React.useCallback(
(node: HTMLButtonElement | null) => {
internalRef.current = node;
if (typeof ref === "function") {
ref(node);
} else if (ref) {
(ref as React.MutableRefObject<HTMLButtonElement | null>).current =
node;
}
},
[ref]
);
React.useEffect(() => {
const node = internalRef.current;
if (!node) {
return;
}
const refs = ctx.itemTriggerRefs.current;
if (!refs.includes(node)) {
refs.push(node);
}
return () => {
const idx = refs.indexOf(node);
if (idx >= 0) {
refs.splice(idx, 1);
}
};
}, [ctx.itemTriggerRefs]);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
onClick?.(event);
if (event.defaultPrevented || item.disabled) {
return;
}
const wasOpen = item.open;
if (ctx.type === "single") {
if (wasOpen) {
if (ctx.collapsible) {
ctx.onValueChange([]);
}
} else {
ctx.onValueChange([item.value]);
}
} else if (wasOpen) {
ctx.onValueChange(ctx.value.filter((v) => v !== item.value));
} else {
ctx.onValueChange([...ctx.value, item.value]);
}
};
const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
onKeyDown?.(event);
if (event.defaultPrevented) {
return;
}
const isVertical = ctx.orientation === "vertical";
const prevKey = isVertical ? "ArrowUp" : "ArrowLeft";
const nextKey = isVertical ? "ArrowDown" : "ArrowRight";
const isPrev = event.key === prevKey;
const isNext = event.key === nextKey;
const isHome = event.key === "Home";
const isEnd = event.key === "End";
if (!(isPrev || isNext || isHome || isEnd)) {
return;
}
const refs = ctx.itemTriggerRefs.current;
const enabled = refs.filter(
(r): r is HTMLButtonElement => !!r && !r.disabled
);
if (enabled.length === 0) {
return;
}
const current = internalRef.current;
const currentIdx = current ? enabled.indexOf(current) : -1;
if (currentIdx < 0) {
return;
}
let target: HTMLButtonElement;
if (isHome) {
target = enabled[0];
} else if (isEnd) {
target = enabled.at(-1) as HTMLButtonElement;
} else if (isPrev) {
target = enabled[(currentIdx - 1 + enabled.length) % enabled.length];
} else {
target = enabled[(currentIdx + 1) % enabled.length];
}
event.preventDefault();
target.focus();
};
return (
<AccordionHeader>
<button
aria-controls={`${item.itemId}-content`}
aria-expanded={item.open}
className={cn(
"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50",
"[&[data-state=open]>svg]:rotate-180",
className
)}
data-disabled={item.disabled ? "" : undefined}
data-slot="accordion-trigger"
data-state={item.open ? "open" : "closed"}
disabled={item.disabled}
id={`${item.itemId}-trigger`}
onClick={handleClick}
onKeyDown={handleKeyDown}
ref={setRef}
type="button"
{...props}
>
{children}
<ChevronDownIcon className="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" />
</button>
</AccordionHeader>
);
}
interface AccordionContentProps extends React.ComponentProps<"div"> {
motion?: string | false;
}
function AccordionContent({
className,
children,
motion: localMotion,
style,
...props
}: AccordionContentProps) {
const ctx = React.useContext(AccordionContext);
const item = React.useContext(AccordionItemContext);
if (!(ctx && item)) {
throw new Error("AccordionContent must be used within AccordionItem");
}
const reduce = useReducedMotion();
const motionProp =
localMotion === false ? "off" : (localMotion ?? ctx.motion);
const motionValue = motionProp ?? defaultMotion;
const gridStyle: React.CSSProperties = {
display: "grid",
gridTemplateRows: item.open ? "1fr" : "0fr",
opacity: item.open ? 1 : 0,
...style,
};
if (reduce) {
gridStyle.transition = "none";
} else {
const transition = getTransition(parseMotion(motionValue));
if (transition) {
gridStyle.transition = transition;
}
}
return (
<div
aria-labelledby={`${item.itemId}-trigger`}
data-disabled={item.disabled ? "" : undefined}
data-slot="accordion-content"
data-state={item.open ? "open" : "closed"}
id={`${item.itemId}-content`}
role="region"
{...props}
>
<div inert={!item.open} style={gridStyle}>
<div style={{ minHeight: 0, overflow: "hidden" }}>
<div className={cn("pt-0 pb-4", className)}>{children}</div>
</div>
</div>
</div>
);
}
export {
Accordion,
AccordionContent,
AccordionHeader,
AccordionItem,
AccordionTrigger,
};Accordion reveals related content in place, one section at a time. It keeps long surfaces compact without requiring a new page or modal.
Installation
$ bunx --bun frakment add accordion$ npx frakment add accordion$ pnpm dlx frakment add accordion$ yarn dlx frakment add accordion
Install the following dependencies:
$ bun add lucide-react$ npm install lucide-react$ pnpm add lucide-react$ yarn add lucide-react
Copy and paste the following code into your project.
"use client";
import { ChevronDownIcon } from "lucide-react";
import * as React from "react";
import { getTransition, parseMotion, useReducedMotion } from "@/lib/motion";
import { cn } from "@/lib/utils";
const defaultMotion = "450 cubic-bezier(0.32, 0.72, 0, 1)";
type AccordionType = "single" | "multiple";
type AccordionOrientation = "horizontal" | "vertical";
interface AccordionContextValue {
collapsible: boolean;
disabled: boolean;
itemTriggerRefs: React.RefObject<(HTMLButtonElement | null)[]>;
motion: string | undefined;
onValueChange: (next: string[]) => void;
orientation: AccordionOrientation;
type: AccordionType;
value: string[];
}
const AccordionContext = React.createContext<AccordionContextValue | null>(
null
);
interface AccordionItemContextValue {
disabled: boolean;
itemId: string;
open: boolean;
value: string;
}
const AccordionItemContext =
React.createContext<AccordionItemContextValue | null>(null);
function normalizeValue(value: string | string[] | undefined): string[] {
if (value === undefined) {
return [];
}
if (Array.isArray(value)) {
return value;
}
return [value];
}
interface AccordionProps
extends Omit<React.ComponentProps<"div">, "defaultValue" | "onChange"> {
collapsible?: boolean;
defaultValue?: string | string[];
disabled?: boolean;
motion?: string;
onValueChange?: ((value: string) => void) | ((value: string[]) => void);
orientation?: AccordionOrientation;
type: AccordionType;
value?: string | string[];
}
function Accordion({
className,
children,
collapsible = false,
defaultValue,
disabled = false,
motion,
onValueChange,
orientation = "vertical",
type,
value: valueProp,
...props
}: AccordionProps) {
const [uncontrolledValue, setUncontrolledValue] = React.useState<string[]>(
() => normalizeValue(defaultValue)
);
const isControlled = valueProp !== undefined;
const value = isControlled ? normalizeValue(valueProp) : uncontrolledValue;
const itemTriggerRefs = React.useRef<(HTMLButtonElement | null)[]>([]);
const setValue = React.useCallback(
(next: string[]) => {
if (!isControlled) {
setUncontrolledValue(next);
}
if (onValueChange) {
if (type === "single") {
(onValueChange as (v: string) => void)(next[0] ?? "");
} else {
(onValueChange as (v: string[]) => void)(next);
}
}
},
[isControlled, onValueChange, type]
);
const ctx: AccordionContextValue = {
collapsible,
disabled,
itemTriggerRefs,
motion,
onValueChange: setValue,
orientation,
type,
value,
};
return (
<AccordionContext.Provider value={ctx}>
<div
className={className}
data-orientation={orientation}
data-slot="accordion"
{...props}
>
{children}
</div>
</AccordionContext.Provider>
);
}
interface AccordionItemProps extends React.ComponentProps<"div"> {
disabled?: boolean;
value: string;
}
function AccordionItem({
className,
children,
disabled = false,
value,
...props
}: AccordionItemProps) {
const ctx = React.useContext(AccordionContext);
if (!ctx) {
throw new Error("AccordionItem must be used within Accordion");
}
const isDisabled = ctx.disabled || disabled;
const open = ctx.value.includes(value);
const itemId = React.useId();
return (
<AccordionItemContext.Provider
value={{ disabled: isDisabled, itemId, open, value }}
>
<div
className={cn("border-b last:border-b-0", className)}
data-disabled={isDisabled ? "" : undefined}
data-slot="accordion-item"
data-state={open ? "open" : "closed"}
{...props}
>
{children}
</div>
</AccordionItemContext.Provider>
);
}
function AccordionHeader({ className, ...props }: React.ComponentProps<"h3">) {
return (
<h3
className={cn("flex", className)}
data-slot="accordion-header"
{...props}
/>
);
}
interface AccordionTriggerProps extends React.ComponentProps<"button"> {}
function AccordionTrigger({
className,
children,
onClick,
onKeyDown,
ref,
...props
}: AccordionTriggerProps) {
const ctx = React.useContext(AccordionContext);
const item = React.useContext(AccordionItemContext);
if (!(ctx && item)) {
throw new Error("AccordionTrigger must be used within AccordionItem");
}
const internalRef = React.useRef<HTMLButtonElement>(null);
const setRef = React.useCallback(
(node: HTMLButtonElement | null) => {
internalRef.current = node;
if (typeof ref === "function") {
ref(node);
} else if (ref) {
(ref as React.MutableRefObject<HTMLButtonElement | null>).current =
node;
}
},
[ref]
);
React.useEffect(() => {
const node = internalRef.current;
if (!node) {
return;
}
const refs = ctx.itemTriggerRefs.current;
if (!refs.includes(node)) {
refs.push(node);
}
return () => {
const idx = refs.indexOf(node);
if (idx >= 0) {
refs.splice(idx, 1);
}
};
}, [ctx.itemTriggerRefs]);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
onClick?.(event);
if (event.defaultPrevented || item.disabled) {
return;
}
const wasOpen = item.open;
if (ctx.type === "single") {
if (wasOpen) {
if (ctx.collapsible) {
ctx.onValueChange([]);
}
} else {
ctx.onValueChange([item.value]);
}
} else if (wasOpen) {
ctx.onValueChange(ctx.value.filter((v) => v !== item.value));
} else {
ctx.onValueChange([...ctx.value, item.value]);
}
};
const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
onKeyDown?.(event);
if (event.defaultPrevented) {
return;
}
const isVertical = ctx.orientation === "vertical";
const prevKey = isVertical ? "ArrowUp" : "ArrowLeft";
const nextKey = isVertical ? "ArrowDown" : "ArrowRight";
const isPrev = event.key === prevKey;
const isNext = event.key === nextKey;
const isHome = event.key === "Home";
const isEnd = event.key === "End";
if (!(isPrev || isNext || isHome || isEnd)) {
return;
}
const refs = ctx.itemTriggerRefs.current;
const enabled = refs.filter(
(r): r is HTMLButtonElement => !!r && !r.disabled
);
if (enabled.length === 0) {
return;
}
const current = internalRef.current;
const currentIdx = current ? enabled.indexOf(current) : -1;
if (currentIdx < 0) {
return;
}
let target: HTMLButtonElement;
if (isHome) {
target = enabled[0];
} else if (isEnd) {
target = enabled.at(-1) as HTMLButtonElement;
} else if (isPrev) {
target = enabled[(currentIdx - 1 + enabled.length) % enabled.length];
} else {
target = enabled[(currentIdx + 1) % enabled.length];
}
event.preventDefault();
target.focus();
};
return (
<AccordionHeader>
<button
aria-controls={`${item.itemId}-content`}
aria-expanded={item.open}
className={cn(
"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50",
"[&[data-state=open]>svg]:rotate-180",
className
)}
data-disabled={item.disabled ? "" : undefined}
data-slot="accordion-trigger"
data-state={item.open ? "open" : "closed"}
disabled={item.disabled}
id={`${item.itemId}-trigger`}
onClick={handleClick}
onKeyDown={handleKeyDown}
ref={setRef}
type="button"
{...props}
>
{children}
<ChevronDownIcon className="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" />
</button>
</AccordionHeader>
);
}
interface AccordionContentProps extends React.ComponentProps<"div"> {
motion?: string | false;
}
function AccordionContent({
className,
children,
motion: localMotion,
style,
...props
}: AccordionContentProps) {
const ctx = React.useContext(AccordionContext);
const item = React.useContext(AccordionItemContext);
if (!(ctx && item)) {
throw new Error("AccordionContent must be used within AccordionItem");
}
const reduce = useReducedMotion();
const motionProp =
localMotion === false ? "off" : (localMotion ?? ctx.motion);
const motionValue = motionProp ?? defaultMotion;
const gridStyle: React.CSSProperties = {
display: "grid",
gridTemplateRows: item.open ? "1fr" : "0fr",
opacity: item.open ? 1 : 0,
...style,
};
if (reduce) {
gridStyle.transition = "none";
} else {
const transition = getTransition(parseMotion(motionValue));
if (transition) {
gridStyle.transition = transition;
}
}
return (
<div
aria-labelledby={`${item.itemId}-trigger`}
data-disabled={item.disabled ? "" : undefined}
data-slot="accordion-content"
data-state={item.open ? "open" : "closed"}
id={`${item.itemId}-content`}
role="region"
{...props}
>
<div inert={!item.open} style={gridStyle}>
<div style={{ minHeight: 0, overflow: "hidden" }}>
<div className={cn("pt-0 pb-4", className)}>{children}</div>
</div>
</div>
</div>
);
}
export {
Accordion,
AccordionContent,
AccordionHeader,
AccordionItem,
AccordionTrigger,
};Update the import paths to match your project setup.
Usage
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";<Accordion collapsible defaultValue="shipping" type="single">
<AccordionItem value="shipping">
<AccordionTrigger>What are your shipping options?</AccordionTrigger>
<AccordionContent>
Standard, express, and overnight options available.
</AccordionContent>
</AccordionItem>
</Accordion>Examples
Basic
A minimal accordion with three items.
"use client";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
const items = [
{
content:
"Click on 'Forgot Password' on the login page, enter your email address, and we'll send you a link to reset your password. The link will expire in 24 hours.",
trigger: "How do I reset my password?",
value: "item-1",
},
{
content:
"Yes, you can upgrade or downgrade your plan at any time from your account settings. Changes will be reflected in your next billing cycle.",
trigger: "Can I change my subscription plan?",
value: "item-2",
},
{
content:
"We accept all major credit cards, PayPal, and bank transfers. All payments are processed securely through our payment partners.",
trigger: "What payment methods do you accept?",
value: "item-3",
},
];
export function AccordionBasic() {
return (
<Accordion
className="w-full max-w-lg"
collapsible
defaultValue="item-1"
type="single"
>
{items.map((item) => (
<AccordionItem key={item.value} value={item.value}>
<AccordionTrigger>{item.trigger}</AccordionTrigger>
<AccordionContent>{item.content}</AccordionContent>
</AccordionItem>
))}
</Accordion>
);
}Multiple
Use type="multiple" to allow several items open at the same time.
"use client";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
const items = [
{
content:
"Manage how you receive notifications. You can enable email alerts for updates or push notifications for mobile devices.",
trigger: "Notification Settings",
value: "notifications",
},
{
content:
"Control your privacy settings and security preferences. Enable two-factor authentication, manage connected devices, review active sessions, and configure data sharing preferences. You can also download your data or delete your account.",
trigger: "Privacy & Security",
value: "privacy",
},
{
content:
"View your current plan, payment history, and upcoming invoices. Update your payment method, change your subscription tier, or cancel your subscription.",
trigger: "Billing & Subscription",
value: "billing",
},
];
export function AccordionMultiple() {
return (
<Accordion
className="w-full max-w-lg"
defaultValue={["notifications"]}
type="multiple"
>
{items.map((item) => (
<AccordionItem key={item.value} value={item.value}>
<AccordionTrigger>{item.trigger}</AccordionTrigger>
<AccordionContent>{item.content}</AccordionContent>
</AccordionItem>
))}
</Accordion>
);
}Disabled
Set disabled on an AccordionItem to lock it.
"use client";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
export function AccordionDisabled() {
return (
<Accordion className="w-full" collapsible type="single">
<AccordionItem value="item-1">
<AccordionTrigger>Can I access my account history?</AccordionTrigger>
<AccordionContent>
Yes, you can view your complete account history including all
transactions, plan changes, and support tickets in the Account History
section of your dashboard.
</AccordionContent>
</AccordionItem>
<AccordionItem disabled value="item-2">
<AccordionTrigger>Premium feature information</AccordionTrigger>
<AccordionContent>
This section contains information about premium features. Upgrade your
plan to access this content.
</AccordionContent>
</AccordionItem>
<AccordionItem value="item-3">
<AccordionTrigger>How do I update my email address?</AccordionTrigger>
<AccordionContent>
You can update your email address in your account settings.
You'll receive a verification email at your new address to
confirm the change.
</AccordionContent>
</AccordionItem>
</Accordion>
);
}Borders
Add borders around the container and between items for a boxed look.
"use client";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
const items = [
{
content:
"We offer monthly and annual subscription plans. Billing is charged at the beginning of each cycle, and you can cancel anytime. All plans include automatic backups, 24/7 support, and unlimited team members.",
trigger: "How does billing work?",
value: "billing",
},
{
content:
"Yes. We use end-to-end encryption, SOC 2 Type II compliance, and regular third-party security audits. All data is encrypted at rest and in transit using industry-standard protocols.",
trigger: "Is my data secure?",
value: "security",
},
{
content:
"We integrate with 500+ popular tools including Slack, Zapier, Salesforce, HubSpot, and more. You can also build custom integrations using our REST API and webhooks.",
trigger: "What integrations do you support?",
value: "integration",
},
];
export function AccordionBorders() {
return (
<Accordion
className="w-full max-w-lg rounded-lg border"
collapsible
defaultValue="billing"
type="single"
>
{items.map((item) => (
<AccordionItem
className="w-full border-b px-4 last:border-b-0"
key={item.value}
value={item.value}
>
<AccordionTrigger>{item.trigger}</AccordionTrigger>
<AccordionContent>{item.content}</AccordionContent>
</AccordionItem>
))}
</Accordion>
);
}Card
Nest an accordion inside a card for grouped, framed content.
"use client";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
const items = [
{
content:
"We offer three subscription tiers: Starter ($9/month), Professional ($29/month), and Enterprise ($99/month). Each plan includes increasing storage limits, API access, priority support, and team collaboration features.",
trigger: "What subscription plans do you offer?",
value: "plans",
},
{
content:
"Billing occurs automatically at the start of each billing cycle. We accept all major credit cards, PayPal, and ACH transfers for enterprise customers. You'll receive an invoice via email after each payment.",
trigger: "How does billing work?",
value: "billing",
},
{
content:
"You can cancel your subscription anytime from your account settings. There are no cancellation fees or penalties. Your access will continue until the end of your current billing period.",
trigger: "How do I cancel my subscription?",
value: "cancel",
},
];
export function AccordionCard() {
return (
<Card className="max-w-sm">
<CardHeader>
<CardTitle>Subscription & Billing</CardTitle>
<CardDescription>
Common questions about your account, plans, payments and
cancellations.
</CardDescription>
</CardHeader>
<CardContent>
<Accordion
className="w-full"
collapsible
defaultValue="plans"
type="single"
>
{items.map((item) => (
<AccordionItem key={item.value} value={item.value}>
<AccordionTrigger>{item.trigger}</AccordionTrigger>
<AccordionContent>{item.content}</AccordionContent>
</AccordionItem>
))}
</Accordion>
</CardContent>
</Card>
);
}In context
FAQ section
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
export function AccordionFaq() {
return (
<Accordion className="w-full max-w-md" collapsible type="single">
<AccordionItem value="ship">
<AccordionTrigger>How do I ship Frakment in my app?</AccordionTrigger>
<AccordionContent>
Copy each primitive into your project with the CLI, then import from
your local `components/ui` directory.
</AccordionContent>
</AccordionItem>
<AccordionItem value="update">
<AccordionTrigger>How do updates work?</AccordionTrigger>
<AccordionContent>
{
"Because every component is local, run `npx frakment add <name>` again and diff the result."
}
</AccordionContent>
</AccordionItem>
</Accordion>
);
}Motion
Accordion accepts a motion prop on the root, inherited by every content item. Pass a per-item override on AccordionContent to diverge from the root setting. Pass motion="off" or motion={false} to disable the reveal.
<Accordion collapsible motion="200 ease-out" type="single">
<AccordionItem value="a">
<AccordionTrigger>Question</AccordionTrigger>
<AccordionContent motion="300 cubic-bezier(0.4, 0, 0.2, 1)">Answer</AccordionContent>
</AccordionItem>
</Accordion>motion follows the same string syntax as every other Frakment component: "off", "150", "150 ease-out", or "150 cubic-bezier(0.4, 0, 0.2, 1)". The default is a 450ms smooth-out curve. prefers-reduced-motion always wins — the reveal is instant when the user has reduced motion enabled.
API Reference
Accordion
| Prop | Type | Default | Description |
|---|---|---|---|
type | singlemultiple | — | Whether one or several items can be open at once. |
defaultValue | stringstring[] | — | Item value(s) open on first render. |
value | stringstring[] | — | Controlled open value(s). |
onValueChange | (value: string) => void(value: string[]) => void | — | Called when the open value changes. Single type receives a string, multiple receives a string array. |
collapsible | boolean | false | When single, allow closing the open item. |
disabled | boolean | false | Prevent all interaction. |
motion | string | — | Motion string for the open/close reveal. Inherited by every item. Pass off to disable. |
orientation | horizontalvertical | vertical | Arrow-key direction. Horizontal uses Left and Right. |
AccordionItem
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Unique identifier for the item. Required. |
disabled | boolean | false | Prevent the item from opening. |
AccordionContent
| Prop | Type | Default | Description |
|---|---|---|---|
motion | stringfalse | — | Per-item override for the reveal motion. Pass false to disable. |
Controlled
const [value, setValue] = React.useState("item-1");
<Accordion onValueChange={setValue} type="single" value={value}>
{/* ... */}
</Accordion>Keyboard
| Key | Action |
|---|---|
Space / Enter | Toggle the focused item |
↑ / ↓ | Move between triggers (vertical orientation) |
← / → | Move between triggers (horizontal orientation) |
Home / End | First / last trigger |
Data Attributes
| Attribute | Values |
|---|---|
data-slot | accordion, accordion-item, accordion-header, accordion-trigger, accordion-content |
data-state | open | closed |
data-orientation | vertical | horizontal |
data-disabled | Present on disabled root, item, trigger, and content |
Accessibility
- Follows the WAI-ARIA disclosure pattern. Triggers expose
aria-expandedandaria-controls; content is labeled witharia-labelledbyand carriesrole="region". AccordionTriggerrenders inside anAccordionHeader(<h3>). Keep trigger text descriptive so the landmark is announced correctly.- Keyboard:
EnterandSpacetoggle an item; arrow keys move focus between triggers;HomeandEndjump to the first or last trigger. - Content stays in the DOM and is marked inert while closed, so screen readers skip it and Tab does not enter it.
Best Practices
- Keep content short per section.
- Use
type="single"for FAQ-style lists. - Use
type="multiple"for settings panels. - Reserve
defaultValuefor one item.
Related Components
- Collapsible: single expandable panel
- Tabs: content panes