mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-02 17:08:39 +00:00
104 lines
2.1 KiB
Plaintext
104 lines
2.1 KiB
Plaintext
---
|
|
title: Accordion
|
|
description: A vertically stacked set of interactive headings that each reveal a section of content.
|
|
component: true
|
|
links:
|
|
doc: https://www.radix-ui.com/docs/primitives/components/accordion
|
|
api: https://www.radix-ui.com/docs/primitives/components/accordion#api-reference
|
|
---
|
|
|
|
<ComponentPreview
|
|
name="accordion-demo"
|
|
className="[&_.preview>[data-orientation=vertical]]:sm:max-w-[70%]"
|
|
description="An accordion with three items"
|
|
/>
|
|
|
|
## Installation
|
|
|
|
<Tabs defaultValue="cli">
|
|
|
|
<TabsList>
|
|
<TabsTrigger value="cli">CLI</TabsTrigger>
|
|
<TabsTrigger value="manual">Manual</TabsTrigger>
|
|
</TabsList>
|
|
|
|
<TabsContent value="cli">
|
|
|
|
```bash
|
|
npx shadcn@latest add accordion
|
|
```
|
|
|
|
</TabsContent>
|
|
|
|
<TabsContent value="manual">
|
|
|
|
<Steps>
|
|
|
|
<Step>Install the following dependencies:</Step>
|
|
|
|
```bash
|
|
npm install @radix-ui/react-accordion
|
|
```
|
|
|
|
<Step>Copy and paste the following code into your project.</Step>
|
|
|
|
<ComponentSource name="accordion" />
|
|
|
|
<Step>Update the import paths to match your project setup.</Step>
|
|
|
|
<Step>Update `tailwind.config.js`</Step>
|
|
|
|
Add the following animations to your `tailwind.config.js` file:
|
|
|
|
```js title="tailwind.config.js" {5-18}
|
|
/** @type {import('tailwindcss').Config} */
|
|
module.exports = {
|
|
theme: {
|
|
extend: {
|
|
keyframes: {
|
|
"accordion-down": {
|
|
from: { height: "0" },
|
|
to: { height: "var(--radix-accordion-content-height)" },
|
|
},
|
|
"accordion-up": {
|
|
from: { height: "var(--radix-accordion-content-height)" },
|
|
to: { height: "0" },
|
|
},
|
|
},
|
|
animation: {
|
|
"accordion-down": "accordion-down 0.2s ease-out",
|
|
"accordion-up": "accordion-up 0.2s ease-out",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
```
|
|
|
|
</Steps>
|
|
|
|
</TabsContent>
|
|
|
|
</Tabs>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import {
|
|
Accordion,
|
|
AccordionContent,
|
|
AccordionItem,
|
|
AccordionTrigger,
|
|
} from "@/components/ui/accordion"
|
|
```
|
|
|
|
```tsx
|
|
<Accordion type="single" collapsible>
|
|
<AccordionItem value="item-1">
|
|
<AccordionTrigger>Is it accessible?</AccordionTrigger>
|
|
<AccordionContent>
|
|
Yes. It adheres to the WAI-ARIA design pattern.
|
|
</AccordionContent>
|
|
</AccordionItem>
|
|
</Accordion>
|
|
```
|