아코디언 (Accordion)
콘텐츠를 접고 펼칠 수 있는 섹션으로 정리할 때 쓰는 아코디언 컴포넌트를 알아볼게요. 아코디언은 복잡한 정보를 시각적 혼란 없이 보여주고 싶을 때 아주 유용해요. 이 문서에서는 기본 사용법부터 상태 관리, 커스터마이징, 고급 전환 적용, 그리고 API 레퍼런스까지 폭넓게 다뤄볼게요.
출처: 문서
본문
<script lang="ts">
import { Accordion } from "bits-ui";
import CaretDown from "phosphor-svelte/lib/CaretDown";
const items = [
{
value: "1",
title: "What is the meaning of life?",
content:
"To become a better person, to help others, and to leave the world a better place than you found it."
},
{
value: "2",
title: "How do I become a better person?",
content:
"Read books, listen to podcasts, and surround yourself with people who inspire you."
},
{
value: "3",
title: "What is the best way to help others?",
content: "Give them your time, attention, and love."
}
];
</script>
<Accordion.Root class="w-full sm:max-w-[70%]" type="multiple">
{#each items as item (item.value)}
<Accordion.Item
value={item.value}
class="border-dark-10 group border-b px-1.5"
>
<Accordion.Header>
<Accordion.Trigger
class="flex w-full flex-1 select-none items-center justify-between py-5 text-[15px] font-medium transition-all [&[data-state=open]>span>svg]:rotate-180"
>
<span class="w-full text-left">
{item.title}
</span>
<span
class="hover:bg-dark-10 inline-flex size-8 items-center justify-center rounded-[7px] bg-transparent"
>
<CaretDown class="size-[18px] transition-transform duration-200" />
</span>
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content
class="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm tracking-[-0.01em]"
>
<div class="pb-[25px]">
{item.content}
</div>
</Accordion.Content>
</Accordion.Item>
{/each}
</Accordion.Root>
개요
아코디언 컴포넌트는 콘텐츠를 접고 펼칠 수 있는 섹션으로 정리하는 다용도 UI 요소예요. 시각적 혼란에 압도되지 않고 특정 정보에 집중할 수 있도록 도와주죠.
빠른 시작
<script lang="ts">
import { Accordion } from "bits-ui";
</script>
<Accordion.Root type="single">
<Accordion.Item value="item-1">
<Accordion.Header>
<Accordion.Trigger>Item 1 Title</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content
>This is the collapsible content for this section.</Accordion.Content
>
</Accordion.Item>
<Accordion.Item value="item-2">
<Accordion.Header>
<Accordion.Trigger>Item 2 Title</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content
>This is the collapsible content for this section.</Accordion.Content
>
</Accordion.Item>
</Accordion.Root>
주요 기능
- 단일 또는 다중 모드: 한 번에 하나의 섹션만 열지, 여러 섹션을 함께 열지 전환할 수 있어요.
- 기본 제공되는 접근성: 내장 ARIA 속성과 키보드 내비게이션 지원.
- 부드러운 전환: 열기/닫기 애니메이션에 CSS 변수나 Svelte 전환을 활용할 수 있어요.
- 유연한 상태: 제어하지 않는 기본값을 쓰거나, 바인딩된 값으로 완전히 제어할 수 있어요.
구조
아코디언은 여러 부분으로 이루어진 컴파운드 컴포넌트예요:
Accordion.Root: 전체 상태를 관리하는 컨테이너Accordion.Item: 개별의 접고 펼칠 수 있는 섹션Accordion.Header: 보이는 헤딩을 담는 부분Accordion.Trigger: 콘텐츠 표시 여부를 토글하는 클릭 가능한 요소Accordion.Content: 접고 펼칠 수 있는 본문 콘텐츠
재사용 가능한 컴포넌트
더 큰 애플리케이션에서 사용을 간결하게 하려면, 반복되는 패턴을 위한 커스텀 래퍼 컴포넌트를 만들면 좋아요. 아래는 재사용 가능한 MyAccordionItem과 MyAccordion의 예시입니다.
아이템 래퍼
Item, Header, Trigger, Content를 하나의 컴포넌트로 합쳐요:
MyAccordionItem.svelte
<script lang="ts">
import { Accordion, type WithoutChildrenOrChild } from "bits-ui";
type Props = WithoutChildrenOrChild<Accordion.ItemProps> & {
title: string;
content: string;
};
let { title, content, ...restProps }: Props = $props();
</script>
<Accordion.Item {...restProps}>
<Accordion.Header>
<Accordion.Trigger>{title}</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content>
{content}
</Accordion.Content>
</Accordion.Item>
아코디언 래퍼
Root를 감싸고 여러 MyAccordionItem 컴포넌트를 렌더링해요:
MyAccordion.svelte
<script lang="ts">
import { Accordion, type WithoutChildrenOrChild } from "bits-ui";
import MyAccordionItem from "$lib/components/MyAccordionItem.svelte";
type Item = {
value?: string;
title: string;
content: string;
disabled?: boolean;
};
let {
value = $bindable(),
ref = $bindable(null),
items,
...restProps
}: WithoutChildrenOrChild<Accordion.RootProps> & {
items: Item[];
} = $props();
</script>
<!--
Since we have to destructure the `value` to make it `$bindable`, we need to use `as any` here to avoid
type errors from the discriminated union of `"single" | "multiple"`.
(an unfortunate consequence of having to destructure bindable values)
-->
<Accordion.Root bind:value bind:ref {...restProps as any}>
{#each items as item, i (item.title + i)}
<MyAccordionItem {...item} />
{/each}
</Accordion.Root>
사용 예시
+page.svelte
<script lang="ts">
import MyAccordion from "$lib/components/MyAccordion.svelte";
const items = [
{ title: "Item 1", content: "Content 1" },
{ title: "Item 2", content: "Content 2" },
];
</script>
<MyAccordion type="single" {items} />
Tip
상태를 프로그래밍 방식으로 제어하려면 각 Item에 고유한 value prop을 사용하세요.
value 상태 관리하기
이 섹션에서는 아코디언의 value 상태를 관리하는 방법을 다뤄요.
양방향 바인딩
단순하고 자동적인 상태 동기화에는 bind:value를 사용해요:
<script lang="ts">
import { Accordion } from "bits-ui";
let myValue = $state<string[]>([]);
const numberOfItemsOpen = $derived(myValue.length);
</script>
<button
onclick={() => {
myValue = ["item-1", "item-2"];
}}
>
Open Items 1 and 2
</button>
<Accordion.Root type="multiple" bind:value={myValue}>
<Accordion.Item value="item-1">
<!-- ... -->
</Accordion.Item>
<Accordion.Item value="item-2">
<!-- ... -->
</Accordion.Item>
<Accordion.Item value="item-3">
<!-- ... -->
</Accordion.Item>
</Accordion.Root>
완전 제어
상태의 읽기와 쓰기를 완전히 제어하려면 함수 바인딩을 사용해요.
<script lang="ts">
import { Accordion } from "bits-ui";
let myValue = $state("");
function getValue() {
return myValue;
}
function setValue(newValue: string) {
myValue = newValue;
}
</script>
<Accordion.Root type="single" bind:value={getValue, setValue}>
<!-- ... -->
</Accordion.Root>
자세한 내용은 State Management 문서를 참고하세요.
커스터마이징
단일 vs. 다중
type prop을 "single"로 설정하면 한 번에 하나의 아코디언 아이템만 열 수 있어요.
<MyAccordion
type="single"
items={[
{ title: "Title A", content: "Content A" },
{ title: "Title B", content: "Content B" },
{ title: "Title C", content: "Content C" },
]}
/>
type prop을 "multiple"로 설정하면 여러 아코디언 아이템을 동시에 열 수 있어요.
<MyAccordion
type="multiple"
items={[
{ title: "Title A", content: "Content A" },
{ title: "Title B", content: "Content B" },
{ title: "Title C", content: "Content C" },
]}
/>
기본으로 열린 아이템
value prop을 설정하면 아이템을 미리 열어둘 수 있어요:
<MyAccordion value={["A", "C"]} type="multiple" />
아이템 비활성화
disabled prop으로 특정 아이템을 비활성화할 수 있어요:
<Accordion.Root type="single">
<Accordion.Item value="item-1" disabled>
<!-- ... -->
</Accordion.Item>
</Accordion.Root>
찾을 때까지 숨김 (Hidden Until Found)
hiddenUntilFound prop은 접힌 아코디언 콘텐츠 안에서 브라우저 검색 기능을 사용할 수 있게 해줘요. 활성화하면 접힌 콘텐츠가 hidden="until-found"로 표시되어, 사용자가 그 안에서 텍스트를 검색하면 브라우저가 아코디언 아이템을 자동으로 펼칩니다.
<Accordion.Root type="single">
<Accordion.Item value="item-1">
<Accordion.Header>
<Accordion.Trigger>Search Demo</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content hiddenUntilFound>
This content can be found by browser search (Ctrl+F/CMD+F) even when the
accordion is closed. The accordion will automatically open when the
browser finds matching text.
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
Svelte 전환
아코디언 컴포넌트는 Svelte의 내장 전환 효과나 다른 애니메이션 라이브러리로 더욱 향상시킬 수 있어요.
forceMount와 child 스니펫 사용하기
아코디언 컴포넌트에 Svelte 전환을 적용하려면 forceMount prop과 child 스니펫을 함께 사용해요. 이 방식을 통해 Accordion.Content의 마운트 동작과 애니메이션을 완전히 제어할 수 있습니다.
<Accordion.Content forceMount={true}>
{#snippet child({ props, open })}
{#if open}
<div {...props} transition:slide={{ duration: 1000 }}>
This is the accordion content that will transition in and out.
</div>
{/if}
{/snippet}
</Accordion.Content>
이 예시에서:
forceMountprop은 컴포넌트가 항상 DOM에 있도록 보장해요.child스니펫은 열림 상태와 컴포넌트 props에 대한 접근을 제공합니다.- Svelte의
#if블록이 콘텐츠가 보이는 시점을 제어해요. - 전환 지시자(
transition:fade와transition:fly)가 애니메이션을 적용합니다.
코드 펼치기
<script lang="ts">
import { Accordion } from "bits-ui";
import CaretDown from "phosphor-svelte/lib/CaretDown";
import { slide } from "svelte/transition";
const items = [
{
title: "What is the meaning of life?",
content:
"To become a better person, to help others, and to leave the world a better place than you found it."
},
{
title: "How do I become a better person?",
content:
"Read books, listen to podcasts, and surround yourself with people who inspire you."
},
{
title: "What is the best way to help others?",
content: "Give them your time, attention, and love."
}
];
let value = $state<string[]>([]);
</script>
<Accordion.Root class="w-full sm:max-w-[70%]" type="multiple" bind:value>
{#each items as item, i (item.title)}
<Accordion.Item value={`${i}`} class="border-dark-10 group border-b px-1.5">
<Accordion.Header>
<Accordion.Trigger
class="flex w-full flex-1 items-center justify-between py-5 text-left text-[15px] font-medium transition-all [&[data-state=open]>span>svg]:rotate-180"
>
{item.title}
<span
class="hover:bg-dark-10 inline-flex size-8 items-center justify-center rounded-[7px] bg-transparent transition-all"
>
<CaretDown class="size-[18px] transition-all duration-200" />
</span>
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content
forceMount={true}
class="overflow-hidden text-sm tracking-[-0.01em]"
>
{#snippet child({ props, open })}
{#if open}
<div {...props} transition:slide={{ duration: 1000 }}>
<div class="pb-[25px]">
{item.content}
</div>
</div>
{/if}
{/snippet}
</Accordion.Content>
</Accordion.Item>
{/each}
</Accordion.Root>
모범 사례
더 깔끔한 코드와 유지보수성을 위해, 이 전환 로직을 캡슐화하는 재사용 가능한 커스텀 컴포넌트를 만드는 것을 고려해보세요.
MyAccordionContent.svelte
<script lang="ts">
import { Accordion, type WithoutChildrenOrChild } from "bits-ui";
import type { Snippet } from "svelte";
import { fade } from "svelte/transition";
let {
ref = $bindable(null),
duration = 200,
children,
...restProps
}: WithoutChildrenOrChild<Accordion.ContentProps> & {
duration?: number;
children: Snippet;
} = $props();
</script>
<Accordion.Content forceMount bind:ref {...restProps}>
{#snippet child({ props, open })}
{#if open}
<div {...props} transition:fade={{ duration }}>
{@render children?.()}
</div>
{/if}
{/snippet}
</Accordion.Content>
그러면 애플리케이션 전반에서 다른 Accordion 프리미티브들과 함께 MyAccordionContent 컴포넌트를 사용할 수 있어요:
<Accordion.Root>
<Accordion.Item value="A">
<Accordion.Header>
<Accordion.Trigger>A</Accordion.Trigger>
</Accordion.Header>
<MyAccordionContent duration={300}>
<!-- ... -->
</MyAccordionContent>
</Accordion.Item>
</Accordion.Root>
예시
다음 예시들은 아코디언 컴포넌트를 다양하게 사용하는 방법을 보여줘요.
가로 카드
아코디언 컴포넌트로 접고 펼칠 수 있는 섹션을 가진 가로 카드 레이아웃을 만들 수 있어요.
코드 펼치기
<script lang="ts">
import { Accordion } from "bits-ui";
let value = $state("item-1");
const items = [
{
id: "item-1",
title: "Mountain Range",
image:
"https://images.unsplash.com/photo-1586589058841-f1264894a260?q=80&w=600&auto=format&fit=crop&ixlib=rb-4.0.3",
description:
"Majestic mountain ranges with snow-capped peaks and lush valleys."
},
{
id: "item-2",
title: "Ocean Views",
image:
"https://images.unsplash.com/photo-1650300874827-7d39bc9276ea?q=80&w=600&auto=format&fit=crop&ixlib=rb-4.0.3",
description:
"Serene ocean scenes with crashing waves, beautiful sunsets, and sandy beaches."
},
{
id: "item-3",
title: "Forest Retreats",
image:
"https://images.unsplash.com/photo-1693297490324-37ee6301f6c8?q=80&w=600&auto=format&fit=crop&ixlib=rb-4.0.3",
description:
"Dense forests with towering trees, abundant wildlife, and peaceful streams."
}
];
</script>
<Accordion.Root
type="single"
orientation="horizontal"
class="flex h-[400px] w-full gap-2 sm:flex-row"
bind:value
>
{#each items as item (item.id)}
<Accordion.Item
value={item.id}
class="ring-primary/70 relative cursor-pointer overflow-hidden rounded-lg transition-all duration-500 ease-in-out data-[state=closed]:w-[20%] data-[state=open]:w-[100%] md:data-[state=closed]:w-[10%] [&:has(:focus-visible)]:ring-2"
onclick={() => (value = item.id)}
>
<img
src={item.image}
alt={item.title}
class="h-[400px] w-full object-cover"
/>
<div
class="absolute inset-0 flex flex-col justify-end bg-gradient-to-t from-black/80 via-black/40 to-transparent p-4"
>
<div
class="transition-all duration-300 group-data-[state=closed]:translate-y-2 group-data-[state=open]:translate-y-0"
>
<Accordion.Header>
<Accordion.Trigger
class="focus-override text-left font-bold text-white transition-all duration-300 focus-visible:!outline-none data-[state=open]:mb-2 data-[state=closed]:text-sm data-[state=open]:text-base data-[state=closed]:opacity-0 data-[state=open]:opacity-100 md:data-[state=open]:text-xl"
>
{item.title}
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Content
forceMount
class="max-h-0 overflow-hidden text-white/90 transition-all duration-700 data-[state=open]:max-h-[100px] data-[state=open]:text-xs data-[state=closed]:opacity-0 data-[state=open]:opacity-100 md:data-[state=open]:text-base"
>
{item.description}
</Accordion.Content>
<div
class="absolute bottom-0 left-0 h-1 w-full transition-all duration-300 group-data-[state=closed]:opacity-0 group-data-[state=open]:opacity-100"
></div>
</div>
</div>
</Accordion.Item>
{/each}
</Accordion.Root>
결제 단계 (Checkout Steps)
아코디언 컴포넌트로 여러 단계의 결제(체크아웃) 과정을 만들 수 있어요.
코드 펼치기
<script lang="ts">
import cn from "clsx";
import { Accordion, useId, Button } from "bits-ui";
import CaretDown from "phosphor-svelte/lib/CaretDown";
import { SvelteSet } from "svelte/reactivity";
let activeStep = $state("");
let completedSteps = new SvelteSet<string>();
</script>
{#snippet MyAccordionHeader({ value, title }: { value: string; title: string })}
{@const isCompleted = completedSteps.has(value)}
<Accordion.Header>
<Accordion.Trigger
class="flex w-full flex-1 select-none items-center justify-between gap-3 py-5 text-[15px] font-medium transition-all [&[data-state=open]>span>svg]:rotate-180"
>
<div
class={cn(
"border-foreground/30 flex size-6 shrink-0 items-center justify-center rounded-full border text-xs font-medium",
isCompleted ? "text-foreground" : "text-muted-foreground"
)}
>
{isCompleted ? "✓" : value}
</div>
<span class="w-full text-left">
{title}
</span>
<span
class="hover:bg-dark-10 inline-flex size-8 items-center justify-center rounded-[7px] bg-transparent"
>
<CaretDown class="size-[18px] transition-transform duration-200" />
</span>
</Accordion.Trigger>
</Accordion.Header>
{/snippet}
{#snippet InputField({
label,
placeholder,
type = "text"
}: {
label: string;
placeholder: string;
type?: string;
})}
{@const id = useId()}
<div class="flex flex-col gap-1">
<label class="select-none text-sm font-medium" for={id}>{label}</label>
<input
{type}
{id}
name={label}
{placeholder}
class="rounded-card-sm border-border-input bg-background placeholder:text-foreground-alt/50 hover:border-dark-40 focus-override inline-flex h-10 w-full items-center border px-4 text-base sm:text-sm"
/>
</div>
{/snippet}
<Accordion.Root
bind:value={activeStep}
class="w-full sm:max-w-[70%]"
type="single"
>
<Accordion.Item value="1" class="border-dark-10 group border-b px-1.5">
{@render MyAccordionHeader({ title: "Shipping Information", value: "1" })}
<Accordion.Content
class="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm tracking-[-0.01em]"
>
<div class="flex flex-col gap-4 pb-6 pt-2">
<div class="grid grid-cols-2 gap-4">
{@render InputField({ label: "First Name", placeholder: "John" })}
{@render InputField({ label: "Last Name", placeholder: "Doe" })}
<div class="col-span-2">
{@render InputField({
label: "Address",
placeholder: "1234 Elm Street"
})}
</div>
{@render InputField({ label: "City", placeholder: "Tampa" })}
{@render InputField({ label: "ZIP", placeholder: "123456" })}
</div>
<div class="pt-2">
<Button.Root
class="rounded-input bg-dark text-background shadow-mini hover:bg-dark/95 inline-flex h-10 select-none items-center justify-center whitespace-nowrap px-[21px] text-sm font-medium transition-all hover:cursor-pointer active:scale-[0.98]"
onclick={() => {
completedSteps.add("1");
activeStep = "2";
}}
>
Continue to Payment
</Button.Root>
</div>
</div>
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="2" class="border-dark-10 group border-b px-1.5">
{@render MyAccordionHeader({ title: "Payment Method", value: "2" })}
<Accordion.Content
class="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm tracking-[-0.01em]"
>
<div class="flex flex-col gap-4 pb-6 pt-2">
<div class="grid grid-cols-3 gap-4">
<div class="col-span-3">
{@render InputField({
label: "Card Number",
placeholder: "4242 4242 4242 4242"
})}
</div>
{@render InputField({ label: "Exp. Month", placeholder: "MM" })}
{@render InputField({ label: "Exp. Year", placeholder: "YY" })}
{@render InputField({ label: "CVC", placeholder: "123" })}
</div>
<div class="pt-2">
<Button.Root
class="rounded-input bg-dark text-background shadow-mini hover:bg-dark/95 inline-flex h-10 select-none items-center justify-center whitespace-nowrap px-[21px] text-sm font-medium transition-all hover:cursor-pointer active:scale-[0.98]"
onclick={() => {
completedSteps.add("2");
activeStep = "3";
}}
>
Continue to Review
</Button.Root>
</div>
</div>
</Accordion.Content>
</Accordion.Item>
<Accordion.Item value="3" class="border-dark-10 group border-b px-1.5">
{@render MyAccordionHeader({ title: "Payment Method", value: "3" })}
<Accordion.Content
class="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden pb-6 text-sm tracking-[-0.01em]"
>
<div class="flex flex-col gap-4 pt-2">
<div class="rounded-lg border p-4">
<h4 class="mb-2 font-medium">Order Summary</h4>
<div class="flex flex-col gap-2">
<div class="flex justify-between text-sm">
<span class="text-muted-foreground">Product 1</span>
<span>$29.99</span>
</div>
<div class="flex justify-between text-sm">
<span class="text-muted-foreground">Product 2</span>
<span>$49.99</span>
</div>
<div class="flex justify-between text-sm">
<span class="text-muted-foreground">Shipping</span>
<span>$4.99</span>
</div>
<div class="mt-2 flex justify-between border-t pt-2 font-medium">
<span>Total</span>
<span>$84.97</span>
</div>
</div>
</div>
<div class="pt-2">
<Button.Root
class="rounded-input bg-dark text-background shadow-mini hover:bg-dark/95 inline-flex h-10 select-none items-center justify-center whitespace-nowrap px-[21px] text-sm font-medium transition-all hover:cursor-pointer active:scale-[0.98]"
onclick={() => {
completedSteps.add("3");
activeStep = "";
}}
>
Place Order
</Button.Root>
</div>
</div>
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>
API 레퍼런스
Accordion.Root
아코디언의 상태를 설정하고 관리하는 루트 아코디언 컴포넌트예요.
| Property | Type | Description | Details |
|---|---|---|---|
type required |
enum - 'single' | 'multiple' |
The type of accordion. If set to 'multiple', the accordion will allow multiple items to be open at the same time. If set to single, the accordion will only allow a single item to be open.Default: —— undefined |
|
value $bindable |
union - string[] | string |
The value of the currently active accordion item. If type is 'single', this should be a string. If type is 'multiple', this should be an array of strings.Default: —— undefined |
|
onValueChange |
function - string | string[] |
A callback function called when the active accordion item value changes. If the type is 'single', the argument will be a string. If type is 'multiple', the argument will be an array of strings.Default: —— undefined |
|
disabled |
boolean |
Whether or not the accordion is disabled. When disabled, the accordion cannot be interacted with.Default: false |
|
loop |
boolean |
Whether or not the accordion should loop through items when reaching the end.Default: false |
|
orientation |
enum - 'vertical' | 'horizontal' |
The orientation of the accordion.Default: 'vertical' |
|
ref $bindable |
HTMLDivElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'vertical' | 'horizontal' |
The orientation of the component. | |
data-disabled |
'' |
Present when the component is disabled. | |
data-accordion-root |
'' |
Present on the root element. |
Accordion.Item
하나의 아코디언 아이템이에요.
| Property | Type | Description | Details |
|---|---|---|---|
disabled |
boolean |
Whether or not the accordion item is disabled.Default: false |
|
value |
string |
The value of the accordion item. This is used to identify when the item is open or closed. If not provided, a unique ID will be generated for this value.Default: A random unique ID |
|
ref $bindable |
HTMLDivElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-state |
enum - 'open' | 'closed' |
Whether the accordion item is open or closed. | |
data-disabled |
'' |
Present when the component is disabled. | |
data-orientation |
enum - 'vertical' | 'horizontal' |
The orientation of the component. | |
data-accordion-item |
'' |
Present on the item element. |
Accordion.Header
아코디언 아이템의 헤더예요.
| Property | Type | Description | Details |
|---|---|---|---|
level |
union - 1 | 2 | 3 | 4 | 5 | 6 |
The heading level of the header. This will be set as the aria-level attribute.Default: 3 |
|
ref $bindable |
HTMLDivElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'vertical' | 'horizontal' |
The orientation of the component. | |
data-disabled |
'' |
Present when the component is disabled. | |
data-heading-level |
enum - '1' | '2' | '3' | '4' | '5' | '6' |
The heading level of the element. | |
data-accordion-header |
'' |
Present on the header element. |
Accordion.Trigger
아코디언 아이템을 토글하는 역할을 하는 버튼이에요.
| Property | Type | Description | Details |
|---|---|---|---|
ref $bindable |
HTMLButtonElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'vertical' | 'horizontal' |
The orientation of the component. | |
data-disabled |
'' |
Present when the component is disabled. | |
data-accordion-trigger |
'' |
Present on the trigger element. |
Accordion.Content
아코디언 아이템이 열렸을 때 표시되는 본문 콘텐츠예요.
| Property | Type | Description | Details |
|---|---|---|---|
forceMount |
boolean |
Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animation library for the content.Default: false |
|
hiddenUntilFound |
boolean |
Whether the content should use hidden='until-found' when closed. This allows browsers to search within collapsed content and automatically expand the accordion item when matches are found.Default: false |
|
ref $bindable |
HTMLDivElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { open: boolean props: Record<string, unknown> } |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'vertical' | 'horizontal' |
The orientation of the component. | |
data-disabled |
'' |
Present when the component is disabled. | |
data-starting-style |
'' |
Present during the initial open frame. Use this to define the starting styles for CSS transitions. | |
data-ending-style |
'' |
Present while closing before unmount. Use this to define the ending styles for CSS transitions. | |
data-accordion-content |
'' |
Present on the content element. |
| CSS Variable | Description | Details |
|---|---|---|
--bits-accordion-content-height |
The height of the accordion content element. | |
--bits-accordion-content-width |
The width of the accordion content element. |
더 알아보기 (Learn more)
아코디언과 함께 쓰면 좋은 개념으로는 상태 관리의 함수 바인딩과 전환의 forceMount·child 조합이 있어요. 컴포넌트를 완전히 바꿔 렌더링하는 법은 child 스니펫 문서에서 확인할 수 있어요.