Components
Accordion
Expandable sections with an animated height, built on Radix.
Sending to another Zuri wallet is free. Cash-out fees are shown before you confirm.
Use Accordion for content people scan and open one piece at a time, such as frequently asked questions. Don't hide anything essential inside one.
Installation
pnpm dlx shadcn@latest add https://components.abdulqadirmsingi.com/r/accordion.json
This adds @radix-ui/react-accordion and two small keyframes (zuri-accordion-down and -up) to your CSS, which animate the height.
Usage
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
<Accordion type="single" collapsible>
<AccordionItem value="fees">
<AccordionTrigger>What are the fees?</AccordionTrigger>
<AccordionContent>Sending to another wallet is free.</AccordionContent>
</AccordionItem>
</Accordion>type="single" keeps one section open (add collapsible so it can also be closed), and type="multiple" lets several stay open.
Several open at once
Props
Accordion takes the Radix root props. The other parts take the Radix props and native element props.
| Prop | Type | Default | Description |
|---|---|---|---|
| type | "single" | "multiple" | – | On Accordion. Required. |
| collapsible | boolean | – | On Accordion with type single. Lets the open section be closed. |
| value / defaultValue / onValueChange | string or string[] | – | On Accordion. Controlled and uncontrolled use. |
| headingLevel | 2 | 3 | 4 | 5 | 6 | 3 | On AccordionTrigger. The heading around the button, to fit your page outline. |
| disabled | boolean | – | On AccordionItem. Skipped by the keyboard and not openable. |
Accessibility
- Each trigger is a real
<button>inside a heading witharia-expanded, and the open panel is aregionnamed by its trigger. - Enter and Space toggle a section. Arrow Down and Up move between triggers, Home and End jump to the first and last, and disabled sections are skipped.
- The chevron is decorative and hidden from screen readers; the state is announced through
aria-expanded. - The height animates using the
--duration-basetoken, which is almost zero underprefers-reduced-motion. - Each trigger is at least 44 pixels tall.
Tokens used
--border, --muted-foreground, --ring, --duration-base, --ease-out.
Known limitations
- The animation changes the panel's height, which is layout. That is cheap for short text but avoid very large panels.
- If you copy the component by hand, remember the two keyframes, or the panels open without animation.
Source
"use client";import * as AccordionPrimitive from "@radix-ui/react-accordion";import { type ComponentProps, createElement } from "react";import { cn } from "@/lib/utils";/** * A stack of sections that expand and collapse. Pass `type="single"` (one open at a time; add * `collapsible` to allow closing it) or `type="multiple"`. */export const Accordion = AccordionPrimitive.Root;export function AccordionItem({ className, ...props}: ComponentProps<typeof AccordionPrimitive.Item>) { return <AccordionPrimitive.Item className={cn("border-b border-border", className)} {...props} />;}export interface AccordionTriggerProps extends ComponentProps<typeof AccordionPrimitive.Trigger> { /** Heading level of the wrapper, so it fits your page outline. Defaults to 3. */ headingLevel?: 2 | 3 | 4 | 5 | 6;}/** The button that toggles a section. It sits inside a real heading, as the pattern requires. */export function AccordionTrigger({ className, children, headingLevel = 3, ...props}: AccordionTriggerProps) { return ( <AccordionPrimitive.Header asChild> {createElement( `h${headingLevel}`, { className: "m-0 flex" }, <AccordionPrimitive.Trigger className={cn( "group flex min-h-11 flex-1 cursor-pointer items-center justify-between gap-4 rounded-md py-3 text-start text-sm font-medium transition-colors duration-[var(--duration-base)] hover:underline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 motion-reduce:transition-none", className, )} {...props} > {children} <svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="size-4 shrink-0 text-muted-foreground transition-transform duration-[var(--duration-base)] ease-[var(--ease-out)] group-data-[state=open]:rotate-180 motion-reduce:transition-none" > <path d="M4 6l4 4 4-4" /> </svg> </AccordionPrimitive.Trigger>, )} </AccordionPrimitive.Header> );}export function AccordionContent({ className, children, ...props}: ComponentProps<typeof AccordionPrimitive.Content>) { return ( <AccordionPrimitive.Content // Height animates with keyframes (declared in this item's css) so Radix can wait for the // exit to finish. Durations are tokens, so reduced motion makes it near-instant. className="overflow-hidden text-sm data-[state=closed]:animate-[zuri-accordion-up_var(--duration-base)_var(--ease-out)] data-[state=open]:animate-[zuri-accordion-down_var(--duration-base)_var(--ease-out)]" {...props} > <div className={cn("pb-4 text-muted-foreground", className)}>{children}</div> </AccordionPrimitive.Content> );}