Accordion
Sections that open and close under their headings, one at a time or independently.
Stacked sections that open under their headings, built on Radix Accordion in React and Reka UI Accordion in Vue. The primitive owns the behaviour; newt/ui owns the look.
Use it for content a reader wants one piece of at a time: a short FAQ, the groups of a settings page, the optional details of a form. If every section should be read, plain headings serve better than making the reader open each one.
newt-accordionimport {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/registry/bases/newt/ui/accordion"
export default function AccordionDemo() {
return (
<Accordion defaultValue="visibility" className="max-w-md">
<AccordionItem value="visibility">
<AccordionTrigger>Who can see this channel?</AccordionTrigger>
<AccordionContent>
Members with the Moderator role, and anyone you add by name.
</AccordionContent>
</AccordionItem>
<AccordionItem value="bans">
<AccordionTrigger>Can I undo a ban?</AccordionTrigger>
<AccordionContent>
Yes. Open the ban list, find the member and choose Revoke.
</AccordionContent>
</AccordionItem>
<AccordionItem value="slowmode">
<AccordionTrigger>What does slowmode do?</AccordionTrigger>
<AccordionContent>
It limits each member to one message per interval in this channel.
</AccordionContent>
</AccordionItem>
</Accordion>
)
}<script setup lang="ts">
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "~~/registry/bases/newt/ui/accordion"
</script>
<template>
<Accordion default-value="visibility" class="max-w-md">
<AccordionItem value="visibility">
<AccordionTrigger>Who can see this channel?</AccordionTrigger>
<AccordionContent>
Members with the Moderator role, and anyone you add by name.
</AccordionContent>
</AccordionItem>
<AccordionItem value="bans">
<AccordionTrigger>Can I undo a ban?</AccordionTrigger>
<AccordionContent>
Yes. Open the ban list, find the member and choose Revoke.
</AccordionContent>
</AccordionItem>
<AccordionItem value="slowmode">
<AccordionTrigger>What does slowmode do?</AccordionTrigger>
<AccordionContent>
It limits each member to one message per interval in this channel.
</AccordionContent>
</AccordionItem>
</Accordion>
</template>Installation
npx newtui@latest add accordionnpx shadcn@latest add @newtui/accordionnpx shadcn-vue@latest add @newtui/accordionpnpm dlx newtui@latest add accordionpnpm dlx shadcn@latest add @newtui/accordionpnpm dlx shadcn-vue@latest add @newtui/accordionyarn dlx newtui@latest add accordionyarn dlx shadcn@latest add @newtui/accordionyarn dlx shadcn-vue@latest add @newtui/accordionbunx newtui@latest add accordionbunx shadcn@latest add @newtui/accordionbunx shadcn-vue@latest add @newtui/accordiondeno run -A npm:newtui@latest add accordiondeno run -A npm:shadcn@latest add @newtui/accordiondeno run -A npm:shadcn-vue@latest add @newtui/accordionvlx newtui@latest add accordionvlx shadcn@latest add @newtui/accordionvlx shadcn-vue@latest add @newtui/accordionvp dlx newtui@latest add accordionvp dlx shadcn@latest add @newtui/accordionvp dlx shadcn-vue@latest add @newtui/accordionnubx newtui@latest add accordionnubx shadcn@latest add @newtui/accordionnubx shadcn-vue@latest add @newtui/accordionnlx newtui@latest add accordionnlx shadcn@latest add @newtui/accordionnlx shadcn-vue@latest add @newtui/accordionupx newtui@latest add accordionupx shadcn@latest add @newtui/accordionupx shadcn-vue@latest add @newtui/accordion- newtui
- shadcn
- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
The shadcn CLI needs the @newtui registry in your components.json. Set it up.
Install the dependencies
npm install radix-uipnpm add radix-uiyarn add radix-uibun add radix-uideno add npm:radix-uivlt install radix-uivp add radix-uinub add radix-uini radix-uiupm add radix-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
npm install reka-uipnpm add reka-uiyarn add reka-uibun add reka-uideno add npm:reka-uivlt install reka-uivp add reka-uinub add reka-uini reka-uiupm add reka-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
Copy the source into your project
"use client"
import { Accordion as AccordionPrimitive } from "radix-ui"
import * as React from "react"
import { cn } from "@/lib/utils"
export type AccordionProps =
| (Omit<AccordionPrimitive.AccordionSingleProps, "type"> & {
/** `single` closes the open section when another opens. */
type?: "single"
})
| AccordionPrimitive.AccordionMultipleProps
/*
* Radix owns the behaviour: which sections are open, the arrow keys, Home and
* End between the headings, and the ids that link each heading to its panel.
* Only the look is newt/ui's. Without a `type` it is `single` and
* `collapsible`, so the open section also closes on a second press.
*/
const Accordion = React.forwardRef<
React.ComponentRef<typeof AccordionPrimitive.Root>,
AccordionProps
>(({ className, ...props }, ref) => {
const classes = cn(
"flex w-full flex-col overflow-hidden rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-surface",
className
)
if (props.type === "multiple") {
return <AccordionPrimitive.Root ref={ref} className={classes} {...props} />
}
return (
<AccordionPrimitive.Root
ref={ref}
collapsible
className={classes}
{...props}
type="single"
/>
)
})
Accordion.displayName = "Accordion"
const AccordionItem = React.forwardRef<
React.ComponentRef<typeof AccordionPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
>(({ className, ...props }, ref) => (
<AccordionPrimitive.Item
ref={ref}
className={cn(
"border-newt-border [&:not(:first-child)]:border-t",
className
)}
{...props}
/>
))
AccordionItem.displayName = "AccordionItem"
/*
* The always-visible line that opens the section. It is a button inside a
* heading, so a screen reader lists the sections among the page's headings.
*/
const AccordionTrigger = React.forwardRef<
React.ComponentRef<typeof AccordionPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Header className="m-0 flex">
<AccordionPrimitive.Trigger
ref={ref}
className={cn(
"group flex flex-1 cursor-pointer items-center justify-between gap-3 border-0 bg-transparent px-4 py-3 text-start text-[15px] font-semibold leading-5 text-newt-text-primary transition-colors duration-fast ease-newt hover:bg-newt-bg-hover",
"focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-newt-text-link",
"disabled:pointer-events-none disabled:opacity-50",
className
)}
{...props}
>
{children}
<svg
viewBox="0 0 16 16"
aria-hidden="true"
className="h-4 w-4 shrink-0 text-newt-text-muted group-data-[state=open]:rotate-90 rtl:-scale-x-100 rtl:group-data-[state=open]:scale-x-100"
>
<path
fill="currentColor"
d="M5.3 3.3a1 1 0 0 1 1.4 0l4 4a1 1 0 0 1 0 1.4l-4 4a1 1 0 0 1-1.4-1.4L8.6 8 5.3 4.7a1 1 0 0 1 0-1.4Z"
/>
</svg>
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
))
AccordionTrigger.displayName = "AccordionTrigger"
const AccordionContent = React.forwardRef<
React.ComponentRef<typeof AccordionPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
>(({ className, ...props }, ref) => (
<AccordionPrimitive.Content
ref={ref}
className={cn(
"px-4 pb-3.5 text-sm leading-5 text-newt-text-secondary",
className
)}
{...props}
/>
))
AccordionContent.displayName = "AccordionContent"
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }<script setup lang="ts">
import {
AccordionRoot,
useForwardPropsEmits,
type AccordionRootEmits,
type AccordionRootProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
/*
* Reka owns the behaviour: which sections are open, the arrow keys, Home and
* End between the headings, and the ids that link each heading to its panel.
* Use `v-model` to control it. Only the look is newt/ui's. Without a `type`
* it is `single` and `collapsible`, so the open section also closes on a
* second press.
*/
const props = withDefaults(
defineProps<AccordionRootProps & { class?: HTMLAttributes["class"] }>(),
{ type: "single", collapsible: true }
)
const emits = defineEmits<AccordionRootEmits>()
const delegated = computed(() => {
const { class: _class, ...rest } = props
return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)
</script>
<template>
<AccordionRoot
v-bind="forwarded"
:class="
cn(
'flex w-full flex-col overflow-hidden rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-surface',
props.class
)
"
>
<slot />
</AccordionRoot>
</template><script setup lang="ts">
import {
AccordionItem,
useForwardProps,
type AccordionItemProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = defineProps<
AccordionItemProps & { class?: HTMLAttributes["class"] }
>()
const delegated = computed(() => {
const { class: _class, ...rest } = props
return rest
})
const forwarded = useForwardProps(delegated)
</script>
<template>
<AccordionItem
v-bind="forwarded"
:class="
cn('border-newt-border [&:not(:first-child)]:border-t', props.class)
"
>
<slot />
</AccordionItem>
</template><script setup lang="ts">
import {
AccordionHeader,
AccordionTrigger,
useForwardProps,
type AccordionTriggerProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
/*
* The always-visible line that opens the section. It is a button inside a
* heading, so a screen reader lists the sections among the page's headings.
*/
const props = defineProps<
AccordionTriggerProps & { class?: HTMLAttributes["class"] }
>()
const delegated = computed(() => {
const { class: _class, ...rest } = props
return rest
})
const forwarded = useForwardProps(delegated)
</script>
<template>
<AccordionHeader class="m-0 flex">
<AccordionTrigger
v-bind="forwarded"
:class="
cn(
'group flex flex-1 cursor-pointer items-center justify-between gap-3 border-0 bg-transparent px-4 py-3 text-start text-[15px] font-semibold leading-5 text-newt-text-primary transition-colors duration-fast ease-newt hover:bg-newt-bg-hover',
'focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-newt-text-link',
'disabled:pointer-events-none disabled:opacity-50',
props.class
)
"
>
<slot />
<svg
viewBox="0 0 16 16"
aria-hidden="true"
class="h-4 w-4 shrink-0 text-newt-text-muted group-data-[state=open]:rotate-90 rtl:-scale-x-100 rtl:group-data-[state=open]:scale-x-100"
>
<path
fill="currentColor"
d="M5.3 3.3a1 1 0 0 1 1.4 0l4 4a1 1 0 0 1 0 1.4l-4 4a1 1 0 0 1-1.4-1.4L8.6 8 5.3 4.7a1 1 0 0 1 0-1.4Z"
/>
</svg>
</AccordionTrigger>
</AccordionHeader>
</template><script setup lang="ts">
import {
AccordionContent,
useForwardProps,
type AccordionContentProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = defineProps<
AccordionContentProps & { class?: HTMLAttributes["class"] }
>()
const delegated = computed(() => {
const { class: _class, ...rest } = props
return rest
})
const forwarded = useForwardProps(delegated)
</script>
<template>
<AccordionContent
v-bind="forwarded"
:class="
cn('px-4 pb-3.5 text-sm leading-5 text-newt-text-secondary', props.class)
"
>
<slot />
</AccordionContent>
</template>export { default as Accordion } from "./Accordion.vue"
export { default as AccordionItem } from "./AccordionItem.vue"
export { default as AccordionTrigger } from "./AccordionTrigger.vue"
export { default as AccordionContent } from "./AccordionContent.vue"Update the import paths
The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Accordion to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Accordion to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
Usage
import { Accordion } from "@/components/ui/accordion"
export function Example() {
return <Accordion />
}<script setup lang="ts">
import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from "@/components/ui/accordion"
</script>
<template>
<Accordion />
</template>Give each AccordionItem a unique value. Put an AccordionTrigger and an AccordionContent inside it. To open a section at the start, pass its value to defaultValue on Accordion.
Examples
Multiple open
With type="multiple" the sections open and close independently, and defaultValue takes a list of values. Use it when a reader compares sections. Keep the default single for a list of questions.
newt-accordionimport {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/registry/bases/newt/ui/accordion"
/*
* `multiple` lets the sections open independently, so opening one leaves the
* others as they are. Here two start open and stay open.
*/
export default function AccordionMultipleDemo() {
return (
<Accordion
type="multiple"
defaultValue={["notifications", "privacy"]}
className="max-w-md"
>
<AccordionItem value="notifications">
<AccordionTrigger>Notifications</AccordionTrigger>
<AccordionContent>
Only mentions, on every device you are signed in to.
</AccordionContent>
</AccordionItem>
<AccordionItem value="privacy">
<AccordionTrigger>Privacy</AccordionTrigger>
<AccordionContent>
Members of this server can message you directly.
</AccordionContent>
</AccordionItem>
<AccordionItem value="appearance">
<AccordionTrigger>Appearance</AccordionTrigger>
<AccordionContent>
Compact messages, with avatars hidden.
</AccordionContent>
</AccordionItem>
</Accordion>
)
}<script setup lang="ts">
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "~~/registry/bases/newt/ui/accordion"
/*
* `multiple` lets the sections open independently, so opening one leaves the
* others as they are. Here two start open and stay open.
*/
</script>
<template>
<Accordion
type="multiple"
:default-value="['notifications', 'privacy']"
class="max-w-md"
>
<AccordionItem value="notifications">
<AccordionTrigger>Notifications</AccordionTrigger>
<AccordionContent>
Only mentions, on every device you are signed in to.
</AccordionContent>
</AccordionItem>
<AccordionItem value="privacy">
<AccordionTrigger>Privacy</AccordionTrigger>
<AccordionContent>
Members of this server can message you directly.
</AccordionContent>
</AccordionItem>
<AccordionItem value="appearance">
<AccordionTrigger>Appearance</AccordionTrigger>
<AccordionContent
>Compact messages, with avatars hidden.</AccordionContent
>
</AccordionItem>
</Accordion>
</template>Custom title
AccordionTrigger takes more than text. Here each heading carries a Badge with a count.
newt-accordionimport {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/registry/bases/newt/ui/accordion"
import { Badge } from "@/registry/bases/newt/ui/badge"
/* The heading takes more than text: here each one carries a count. */
export default function AccordionCustomTitleDemo() {
return (
<Accordion defaultValue="reports" className="max-w-md">
<AccordionItem value="reports">
<AccordionTrigger>
<span className="flex items-center gap-2">
Open reports
<Badge variant="danger">3</Badge>
</span>
</AccordionTrigger>
<AccordionContent>
Two for spam in the lounge, one for a display name.
</AccordionContent>
</AccordionItem>
<AccordionItem value="requests">
<AccordionTrigger>
<span className="flex items-center gap-2">
Join requests
<Badge variant="brand">12</Badge>
</span>
</AccordionTrigger>
<AccordionContent>
Twelve people are waiting for a moderator to let them in.
</AccordionContent>
</AccordionItem>
<AccordionItem value="appeals">
<AccordionTrigger>
<span className="flex items-center gap-2">
Appeals
<Badge>0</Badge>
</span>
</AccordionTrigger>
<AccordionContent>
Nobody has appealed a ban this week.
</AccordionContent>
</AccordionItem>
</Accordion>
)
}<script setup lang="ts">
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "~~/registry/bases/newt/ui/accordion"
import { Badge } from "~~/registry/bases/newt/ui/badge"
/* The heading takes more than text: here each one carries a count. */
</script>
<template>
<Accordion default-value="reports" class="max-w-md">
<AccordionItem value="reports">
<AccordionTrigger>
<span class="flex items-center gap-2">
Open reports
<Badge variant="danger">3</Badge>
</span>
</AccordionTrigger>
<AccordionContent>
Two for spam in the lounge, one for a display name.
</AccordionContent>
</AccordionItem>
<AccordionItem value="requests">
<AccordionTrigger>
<span class="flex items-center gap-2">
Join requests
<Badge variant="brand">12</Badge>
</span>
</AccordionTrigger>
<AccordionContent>
Twelve people are waiting for a moderator to let them in.
</AccordionContent>
</AccordionItem>
<AccordionItem value="appeals">
<AccordionTrigger>
<span class="flex items-center gap-2">
Appeals
<Badge>0</Badge>
</span>
</AccordionTrigger>
<AccordionContent>Nobody has appealed a ban this week.</AccordionContent>
</AccordionItem>
</Accordion>
</template>API reference
Accordion
type?"single" | "multiple"
`single` closes the open section when another opens. `multiple` lets them open independently.
"single" | "multiple""single"value / v-model?string | string[]
The open section, or the list of open sections when `type` is `multiple`. Leave it out and pass `defaultValue` to let the accordion own it.
string | string[]defaultValue?string | string[]
The section or sections that start open.
string | string[]onValueChange?(value: string | string[]) => void
React only. Called when a section opens or closes; Vue emits `update:modelValue`.
(value: string | string[]) => voidcollapsible?boolean
Only for `single`. When `false`, a press on the open section does not close it.
booleantruedisabled?boolean
Stops every section from opening or closing.
booleanfalseAccordionItem
value?string
Required. The name of the section, unique in the accordion.
stringdisabled?boolean
Stops this section from opening or closing.
booleanfalseAccordionTrigger renders a button inside an <h3>, followed by the chevron. AccordionContent renders the panel, which is removed from the page while the section is closed. Every part also accepts the native attributes of the element it renders, and a className that is merged rather than replaced.
Accessibility
Each trigger is a button inside a heading and carries aria-expanded and aria-controls for its panel. The panel is a role="region" named by its trigger. Enter and Space toggle a section. Tab moves between triggers, and so do the Down and Up arrow keys, Home and End. A disabled trigger is dimmed and takes no focus. Write a title that makes sense alone, because a screen reader user moves through the titles before opening any. The chevron is decoration, turns a quarter when the section is open, and is mirrored in right-to-left text.
A closed panel is not in the page, so find-in-page does not match text inside it. In Vue, pass :unmount-on-hide="false" to Accordion to keep closed panels in the page; a find-in-page match then opens the section.
Tokens
Accordion reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-accordion.
--newt-border--newt-radius-md--newt-bg-surface--newt-text-primary--newt-duration-fast--newt-ease--newt-bg-hover--newt-text-link--newt-text-muted--newt-dir--newt-text-secondary