Accordion
A vertically stacked set of interactive headings that each reveal a section of content.
React is a JavaScript library for building user interfaces.
Solid is a JavaScript library for building user interfaces.
Vue is a JavaScript library for building user interfaces.
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger,} from '@/components/ui/accordion';
export const Basic = () => { return ( <Accordion defaultValue={['React']} className="max-w-[400px] w-full"> {['React', 'Solid', 'Vue'].map((item) => ( <AccordionItem key={item} value={item} className="w-full"> <AccordionTrigger className="w-full bg-transparent"> What is {item}? </AccordionTrigger> <AccordionContent> {item} is a JavaScript library for building user interfaces. </AccordionContent> </AccordionItem> ))} </Accordion> );};
Installation
-
Run the following command:
npx borristw-ui@latest add accordionyarn borristw-ui@latest add accordionpnpm borristw-ui@latest add accordion -
Update
tailwind.config.js
Add the following animations to your
tailwind.config.js
file:tailwind.config.js /** @type {import('tailwindcss').Config} */module.exports = {theme: {extend: {keyframes: {'accordion-down': {from: { height: '0' },to: { height: 'var(--height)' },},'accordion-up': {from: { height: 'var(--height)' },to: { height: '0' },},},animation: {'accordion-down': 'accordion-down 0.2s ease-out','accordion-up': 'accordion-up 0.2s ease-out',},},},};
-
Install the following dependencies:
npm i @ark-ui/reactyarn add @ark-ui/reactpnpm add @ark-ui/react -
Copy and paste the following code into your project.
-
Update the import paths to match your project setup.
-
Update
tailwind.config.js
Add the following animations to your
tailwind.config.js
file:tailwind.config.js /** @type {import('tailwindcss').Config} */module.exports = {theme: {extend: {keyframes: {'accordion-down': {from: { height: '0' },to: { height: 'var(--height)' },},'accordion-up': {from: { height: 'var(--height)' },to: { height: '0' },},},animation: {'accordion-down': 'accordion-down 0.2s ease-out','accordion-up': 'accordion-up 0.2s ease-out',},},},};
Usage
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger,} from '@/components/ui/accordion';
<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>