# Accordion URL: /lynx/components/accordion Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/accordion.mdx A component that keeps screens clean and organized by collapsing and expanding related information sections. Lynx Engine 최소 버전: 3.6 사용 가능 버전: @seed-design/lynx-react@0.5.0, @seed-design/lynx-css@0.9.0 ## Preview ```tsx import "./styles"; import { Box, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 첫 번째 항목의 내용입니다. 두 번째 항목의 내용입니다. 세 번째 항목의 내용입니다. ); } ``` ## Installation - npm: npx @seed-design/cli@latest add ui:accordion - pnpm: pnpm dlx @seed-design/cli@latest add ui:accordion - yarn: yarn dlx @seed-design/cli@latest add ui:accordion - bun: bun x @seed-design/cli@latest add ui:accordion ## Props ### `Accordion` ### `AccordionItem` ### `AccordionTrigger` ### `AccordionContent` ## Examples ### Inline Variant The default variant. Items are displayed in a continuous flow with dividing lines between items. ```tsx import "./styles"; import { Box, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 첫 번째 항목의 내용입니다. 두 번째 항목의 내용입니다. 세 번째 항목의 내용입니다. ); } ``` ### Separated Using `variant="separated"` displays each item as a separate card. ```tsx import "./styles"; import { Box, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 첫 번째 항목의 내용입니다. 두 번째 항목의 내용입니다. 세 번째 항목의 내용입니다. ); } ``` ### Multiple By default, only one item can be expanded at a time. Using the `multiple` prop allows multiple items to be expanded simultaneously. ```tsx import "./styles"; import { Box, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 여러 항목을 동시에 펼칠 수 있습니다. 각 항목은 다른 항목과 독립적으로 열고 닫힙니다. 세 번째 항목의 내용입니다. ); } ``` ### Always one open When using `values` and `onValuesChange` with a controlled pattern, you can ensure that one item is always open by adding a guard that prevents the setter from being called when an empty array is received. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { Box, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [values, setValues] = useState(["item-1"]); function handleValuesChange(nextValues: string[]) { "background only"; if (nextValues.length === 0) return; setValues(nextValues); } return ( 현재 항목은 다시 눌러도 닫히지 않고, 다른 항목을 선택할 때만 전환됩니다. 평일 오후 2시 이전 주문은 당일 출고되며, 주말 주문은 다음 영업일에 출고됩니다. 수령 후 7일 이내에 교환 또는 반품을 요청할 수 있습니다. ); } ``` ### Size Set the size of the Accordion using `size`. (default: `medium`) Lynx supports `medium` and `large`. The `responsive` option that automatically changes based on screen width is not supported, so you should select one of the two values based on screen width in your app if needed. ```tsx import "./styles"; import { Box, Text, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 항목의 내용입니다. 항목의 내용입니다. ); } ``` ### Prefix You can pass leading elements like icons to the `prefix` prop. ```tsx import "./styles"; import IconCardLine from "@karrotmarket/lynx-monochrome-icon/IconCardLine"; import IconQuestionmarkCircleLine from "@karrotmarket/lynx-monochrome-icon/IconQuestionmarkCircleLine"; import IconTruckLine from "@karrotmarket/lynx-monochrome-icon/IconTruckLine"; import { Box, Icon, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( } size="full" />} title="배송 방법" /> 일반 배송, 빠른 배송, 방문 수령 중 주문 상황에 맞는 방법을 선택할 수 있습니다. } size="full" />} title="결제 및 쿠폰" /> 카드, 간편결제, 보유 쿠폰을 한 번에 확인하고 결제에 적용할 수 있습니다. } size="full" />} title="문의와 환불" /> 주문 취소 가능 시간, 환불 소요 기간, 고객센터 문의 방법을 확인할 수 있습니다. ); } ``` ### Description You can add supplementary descriptions to the trigger using the `description` prop. ```tsx import "./styles"; import { Box, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 첫 번째 항목의 내용입니다. 두 번째 항목의 내용입니다. 세 번째 항목의 내용입니다. ); } ``` ### Disabled You can disable all or individual items using the `disabled` prop. - Setting `disabled` on `Accordion` disables all items. - Setting `disabled` on `AccordionItem` disables only that item. ```tsx import "./styles"; import { Box, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 이 항목은 활성화 상태입니다. 이 항목은 비활성화 상태입니다. 이 항목은 활성화 상태입니다. ); } ``` ### Controlled You can directly control the open state using `values` and `onValuesChange`. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { Box, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [values, setValues] = useState(["item-1"]); function handleValuesChange(nextValues: string[]) { "background only"; setValues(nextValues); } return ( 첫 번째 항목의 내용입니다. 두 번째 항목의 내용입니다. 세 번째 항목의 내용입니다. ); } ``` ### Value Array Changes In controlled mode, the currently open items are passed as a `values` array. The example below shows the latest `values` and recent `onValuesChange` results each time the trigger is clicked. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { Box, HStack, Text, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; const DEFAULT_VALUES = ["shipping"]; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [values, setValues] = useState(DEFAULT_VALUES); const [history, setHistory] = useState([DEFAULT_VALUES]); function handleValuesChange(nextValues: string[]) { "background only"; setValues(nextValues); setHistory((previous) => [nextValues, ...previous].slice(0, 5)); } return ( 빠른 배송, 새벽 배송, 방문 수령 옵션을 비교할 수 있습니다. 카드, 계좌이체, 간편결제 중에서 원하는 결제 수단을 선택할 수 있습니다. 주문 취소 가능 시간과 환불 소요 기간을 확인할 수 있습니다. values: {JSON.stringify(values)} onValuesChange history: {history.map((snapshot, index) => ( {index + 1}. {JSON.stringify(snapshot)} ))} ); } ``` ### Default Expanded You can specify the initial open state using `defaultValues`. ```tsx import "./styles"; import { Box, Text, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 첫 번째 항목은 기본으로 펼쳐진 상태입니다. 두 번째 항목의 내용입니다. 세 번째 항목의 내용입니다. ); } ``` ### Custom Content `AccordionContent` serves only as an open/close animation container. It does not provide default padding, background color, borders, or typography styles, so you must configure these directly in the internal content. We recommend the pattern of explicitly providing padding and background using `Box` as shown in the example below. ```tsx import "./styles"; import { Box, Text, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 일반 배송 주문 후 영업일 기준 2-3일 내에 배송됩니다. 제주 및 도서산간 지역은 1-2일이 추가 소요될 수 있습니다. 1. 고객센터로 반품/교환 요청 2. 상품 수거 (택배 방문 수거) 3. 검수 후 환불 또는 교환 처리 ); } ``` ## Web Version Differences The Lynx `Accordion` has the following differences from the React version. - **Native elements**: Renders Lynx `` and `` instead of HTML heading, button, and region. - **Interaction**: Opens and closes items via the Trigger's native tap event instead of keyboard navigation. - **Accessibility**: Uses `accessibility-heading`, `accessibility-role-description`, and `accessibility-value` instead of DOM ARIA. - **Responsive size**: Lynx preset does not support viewport media queries, so `size="responsive"` is not provided. - **Content transition**: The React version passes height via CSS custom property, while the Lynx version measures content height with `layoutchange` and applies transitions with the same duration and easing. ## Unsupported Lynx Features | Feature | Description | | --------------------------------- | ------------------------------------------------------------------------------------------------------------ | | `asChild` | Lynx does not have Slot-based polymorphic rendering. | | `headingLevel` | Lynx heading accessibility attributes do not accept HTML heading levels. | | DOM ARIA Connection | Use Lynx native accessibility attributes instead of `aria-controls`, `aria-labelledby`, and `role="region"`. | | Arrow / Home / End Key Navigation | Lynx native screens do not have a keyboard focus model like the web. | | `size="responsive"` | Lynx preset does not support viewport media queries. |