본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Dropdown Menu 문서

원문 보기 위키 갱신

Dropdown Menu는 트리거(보통 버튼)를 눌렀을 때 선택 가능한 항목들의 메뉴를 보여 주는 컴포넌트예요. 액션 메뉴나 설정 메뉴처럼 여러 선택지를 정돈해서 제시할 때 특히 유용해요.

출처: 문서

본문

<script lang="ts">
  import { Avatar, DropdownMenu } from "bits-ui";
  import Cardholder from "phosphor-svelte/lib/Cardholder";
  import CaretRight from "phosphor-svelte/lib/CaretRight";
  import DotsThree from "phosphor-svelte/lib/DotsThree";
  import GearSix from "phosphor-svelte/lib/GearSix";
  import UserCircle from "phosphor-svelte/lib/UserCircle";
  import UserCirclePlus from "phosphor-svelte/lib/UserCirclePlus";
  import Bell from "phosphor-svelte/lib/Bell";
  import Check from "phosphor-svelte/lib/Check";
  import DotOutline from "phosphor-svelte/lib/DotOutline";
  let notifications = $state<boolean>(false);
  let invited = $state("");
</script>
<DropdownMenu.Root>
  <DropdownMenu.Trigger
    class="border-input text-foreground shadow-btn hover:bg-muted inline-flex h-10 w-10 select-none items-center justify-center rounded-full border text-sm font-medium active:scale-[0.98]"
  >
    <DotsThree class="text-foreground h-6 w-6" />
  </DropdownMenu.Trigger>
  <DropdownMenu.Portal>
    <DropdownMenu.Content
      class="border-muted bg-background shadow-popover outline-hidden focus-visible:outline-hidden w-[229px] rounded-xl border px-1 py-1.5"
      sideOffset={8}
    >
      <DropdownMenu.Item
        class="rounded-button data-highlighted:bg-muted ring-0! ring-transparent! flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
      >
        <div class="flex items-center">
          <UserCircle class="text-foreground-alt mr-2 size-5" />
          Profile
        </div>
        <div class="ml-auto flex items-center gap-px">
          <kbd
            class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-xs"
          >
            ⌘
          </kbd>
          <kbd
            class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-[10px]"
          >
            P
          </kbd>
        </div>
      </DropdownMenu.Item>
      <DropdownMenu.Item
        class="rounded-button data-highlighted:bg-muted ring-0! ring-transparent! flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
      >
        <div class="flex items-center">
          <Cardholder class="text-foreground-alt mr-2 size-5" />
          Billing
        </div>
        <div class="ml-auto flex items-center gap-px">
          <kbd
            class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-xs"
          >
            ⌘
          </kbd>
          <kbd
            class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-[10px]"
          >
            B
          </kbd>
        </div>
      </DropdownMenu.Item>
      <DropdownMenu.Item
        class="rounded-button data-highlighted:bg-muted ring-0! ring-transparent! flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
      >
        <div class="flex items-center">
          <GearSix class="text-foreground-alt mr-2 size-5" />
          Settings
        </div>
        <div class="ml-auto flex items-center gap-px">
          <kbd
            class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-xs"
          >
            ⌘
          </kbd>
          <kbd
            class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-[10px]"
          >
            S
          </kbd>
        </div>
      </DropdownMenu.Item>
      <DropdownMenu.CheckboxItem
        bind:checked={notifications}
        class="rounded-button data-highlighted:bg-muted ring-0! ring-transparent! flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
      >
        {#snippet children({ checked })}
          <div class="flex items-center pr-4">
            <Bell class="text-foreground-alt mr-2 size-5" />
            Notifications
          </div>
          <div class="ml-auto flex items-center gap-px">
            {#if checked}
              <Check class="size-4" />
            {/if}
          </div>
        {/snippet}
      </DropdownMenu.CheckboxItem>
      <DropdownMenu.Sub>
        <DropdownMenu.SubTrigger
          class="rounded-button data-highlighted:bg-muted data-[state=open]:bg-muted ring-0! ring-transparent! flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
        >
          <div class="flex items-center">
            <UserCirclePlus class="text-foreground-alt mr-2 size-5" />
            Workspace
          </div>
          <div class="ml-auto flex items-center gap-px">
            <CaretRight class="text-foreground-alt size-5" />
          </div>
        </DropdownMenu.SubTrigger>
        <DropdownMenu.Portal>
          <DropdownMenu.SubContent
            class="border-muted bg-background shadow-popover ring-0! ring-transparent! w-[209px] rounded-xl border px-1 py-1.5 outline-none"
            sideOffset={10}
          >
            <DropdownMenu.RadioGroup bind:value={invited}>
              <DropdownMenu.RadioItem
                value="huntabyte"
                class="rounded-button data-highlighted:bg-muted ring-0! ring-transparent! flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
              >
                {#snippet children({ checked })}
                  <Avatar.Root
                    class="border-foreground/50 relative mr-3 flex size-5 shrink-0 overflow-hidden rounded-full border"
                  >
                    <Avatar.Image
                      src="https://github.com/huntabyte.png"
                      alt="@huntabyte"
                      class="aspect-square h-full w-full"
                    />
                    <Avatar.Fallback
                      class="bg-muted text-xxs flex h-full w-full items-center justify-center rounded-full"
                      >HJ</Avatar.Fallback
                    >
                  </Avatar.Root>
                  @huntabyte
                  {#if checked}
                    <DotOutline class="ml-auto size-4" />
                  {/if}
                {/snippet}
              </DropdownMenu.RadioItem>
              <DropdownMenu.RadioItem
                value="pavel"
                class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
              >
                {#snippet children({ checked })}
                  <Avatar.Root
                    class="border-foreground/50 relative mr-3 flex size-5 shrink-0 overflow-hidden rounded-full border"
                  >
                    <Avatar.Image
                      src="https://github.com/pavelstianko.png"
                      alt="@pavel_stianko"
                      class="aspect-square h-full w-full"
                    />
                    <Avatar.Fallback
                      class="bg-muted flex h-full w-full items-center justify-center rounded-full text-xs"
                      >PS</Avatar.Fallback
                    >
                  </Avatar.Root>
                  @pavel_stianko
                  {#if checked}
                    <DotOutline class="ml-auto size-4" />
                  {/if}
                {/snippet}
              </DropdownMenu.RadioItem>
              <DropdownMenu.RadioItem
                value="cokakoala"
                class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
              >
                {#snippet children({ checked })}
                  <Avatar.Root
                    class="border-foreground/50 relative mr-3 flex size-5 shrink-0 overflow-hidden rounded-full border"
                  >
                    <Avatar.Image
                      src="https://github.com/adriangonz97.png"
                      alt="@cokakoala_"
                      class="aspect-square h-full w-full"
                    />
                    <Avatar.Fallback
                      class="bg-muted flex h-full w-full items-center justify-center rounded-full text-xs"
                      >CK</Avatar.Fallback
                    >
                  </Avatar.Root>
                  @cokakoala_
                  {#if checked}
                    <DotOutline class="ml-auto size-4" />
                  {/if}
                {/snippet}
              </DropdownMenu.RadioItem>
              <DropdownMenu.RadioItem
                value="tglide"
                class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
              >
                {#snippet children({ checked })}
                  <Avatar.Root
                    class="border-foreground/50 relative mr-3 flex size-5 shrink-0 overflow-hidden rounded-full border"
                  >
                    <Avatar.Image
                      src="https://github.com/tglide.png"
                      alt="@tglide"
                      class="aspect-square h-full w-full"
                    />
                    <Avatar.Fallback
                      class="bg-muted flex h-full w-full items-center justify-center rounded-full text-xs"
                    >
                      TL
                    </Avatar.Fallback>
                  </Avatar.Root>
                  @thomasglopes
                  {#if checked}
                    <DotOutline class="ml-auto size-4" />
                  {/if}
                {/snippet}
              </DropdownMenu.RadioItem>
            </DropdownMenu.RadioGroup>
          </DropdownMenu.SubContent>
        </DropdownMenu.Portal>
      </DropdownMenu.Sub>
    </DropdownMenu.Content>
  </DropdownMenu.Portal>
</DropdownMenu.Root>

구조 (Structure)

기본 구조는 Root 안에 Trigger와 Content를 두고, Content 안에 Item 같은 메뉴 항목을 배치하는 형태예요.

<script lang="ts">
  import { DropdownMenu } from "bits-ui";
</script>
<DropdownMenu.Root>
  <DropdownMenu.Trigger />
  <DropdownMenu.Portal>
    <DropdownMenu.Content>
      <DropdownMenu.Group>
        <DropdownMenu.GroupHeading />
        <DropdownMenu.Item />
      </DropdownMenu.Group>
      <DropdownMenu.Group>
        <DropdownMenu.Item />
      </DropdownMenu.Group>
      <DropdownMenu.Item />
      <DropdownMenu.CheckboxItem />
      <DropdownMenu.RadioGroup>
        <DropdownMenu.RadioItem />
      </DropdownMenu.RadioGroup>
      <DropdownMenu.CheckboxGroup>
        <DropdownMenu.CheckboxItem />
      </DropdownMenu.CheckboxGroup>
      <DropdownMenu.Sub>
        <DropdownMenu.SubTrigger />
        <DropdownMenu.Portal>
          <DropdownMenu.SubContent />
        </DropdownMenu.Portal>
      </DropdownMenu.Sub>
      <DropdownMenu.Separator />
      <DropdownMenu.Arrow />
    </DropdownMenu.Content>
  </DropdownMenu.Portal>
</DropdownMenu.Root>

재사용 컴포넌트 (Reusable Components)

Dropdown Menu를 여러 곳에서 쓸 계획이라면, Dropdown Menu 컴포넌트를 감싸는 재사용 가능한 컴포넌트를 만들 수 있어요.

아래 예시는 기능을 더 풍부하게 만드는 몇 가지 커스텀 props를 받는 Dropdown Menu 컴포넌트를 만드는 방법을 보여 줘요.

<script lang="ts">
  import type { Snippet } from "svelte";
  import { DropdownMenu, type WithoutChild } from "bits-ui";
  type Props = DropdownMenu.RootProps & {
    buttonText: string;
    items: string[];
    contentProps?: WithoutChild<DropdownMenu.ContentProps>;
    // other component props if needed
  };
  let {
    open = $bindable(false),
    children,
    buttonText,
    items,
    contentProps,
    ...restProps
  }: Props = $props();
</script>
<DropdownMenu.Root bind:open {...restProps}>
  <DropdownMenu.Trigger>
    {buttonText}
  </DropdownMenu.Trigger>
  <DropdownMenu.Portal>
    <DropdownMenu.Content {...contentProps}>
      <DropdownMenu.Group aria-label={buttonText}>
        {#each items as item}
          <DropdownMenu.Item textValue={item}>
            {item}
          </DropdownMenu.Item>
        {/each}
      </DropdownMenu.Group>
    </DropdownMenu.Content>
  </DropdownMenu.Portal>
</DropdownMenu.Root>

만든 MyDropdownMenu 컴포넌트는 이렇게 사용하면 돼요.

<script lang="ts">
  import MyDropdownMenu from "./MyDropdownMenu.svelte";
</script>
<MyDropdownMenu
  buttonText="Select a manager"
  items={["Michael Scott", "Dwight Schrute", "Jim Halpert"]}
/>

열림 상태 관리 (Managing Open State)

이번엔 메뉴의 open 상태를 관리하는 방법을 알아볼게요.

양방향 바인딩 (Two-Way Binding)

간단하고 자동적인 상태 동기화는 bind:open으로 처리해요.

<script lang="ts">
  import { DropdownMenu } from "bits-ui";
  let isOpen = $state(false);
</script>
<button onclick={() => (isOpen = true)}>Open Context Menu</button>
<DropdownMenu.Root bind:open={isOpen}>
  <!-- ... -->
</DropdownMenu.Root>

완전 제어 (Fully Controlled)

상태의 읽기와 쓰기를 전부 제어하고 싶다면 Function Binding을 사용해요.

<script lang="ts">
  import { DropdownMenu } from "bits-ui";
  let myOpen = $state(false);
  function getOpen() {
    return myOpen;
  }
  function setOpen(newOpen: boolean) {
    myOpen = newOpen;
  }
</script>
<DropdownMenu.Root bind:open={getOpen, setOpen}>
  <!-- ... -->
</DropdownMenu.Root>

그룹 (Groups)

관련 메뉴 항목을 묶으려면 DropdownMenu.Group 컴포넌트를 사용하고, DropdownMenu.GroupHeading이나 DropdownMenu.Group 컴포넌트의 aria-label 속성으로 라벨을 붙여 주면 돼요.

<DropdownMenu.Group>
  <DropdownMenu.GroupHeading>File</DropdownMenu.GroupHeading>
  <DropdownMenu.Item>New</DropdownMenu.Item>
  <DropdownMenu.Item>Open</DropdownMenu.Item>
  <DropdownMenu.Item>Save</DropdownMenu.Item>
  <DropdownMenu.Item>Save As</DropdownMenu.Item>
</DropdownMenu.Group>
<!-- or -->
<DropdownMenu.Group aria-label="file">
  <DropdownMenu.Item>New</DropdownMenu.Item>
  <DropdownMenu.Item>Open</DropdownMenu.Item>
  <DropdownMenu.Item>Save</DropdownMenu.Item>
  <DropdownMenu.Item>Save As</DropdownMenu.Item>
</DropdownMenu.Group>

그룹 헤딩 (Group Heading)

DropdownMenu.GroupHeading 컴포넌트는 DropdownMenu.Group이나 DropdownMenu.RadioGroup 컴포넌트의 자식이어야 해요. 단독으로 쓰면 개발 중에 오류가 발생해요.

<DropdownMenu.Group>
  <DropdownMenu.GroupHeading>File</DropdownMenu.GroupHeading>
  <!-- ... items here -->
</DropdownMenu.Group>
<!-- or -->
<DropdownMenu.RadioGroup>
  <DropdownMenu.GroupHeading>Favorite color</DropdownMenu.GroupHeading>
  <!-- ... radio items here -->
</DropdownMenu.RadioGroup>

라디오 그룹 (Radio Groups)

DropdownMenu.RadioGroup과 DropdownMenu.RadioItem 컴포넌트를 조합하면 메뉴 안에 라디오 그룹을 만들 수 있어요.

<script lang="ts">
  import { DropdownMenu } from "bits-ui";
  const values = ["one", "two", "three"];
  let value = $state("one");
</script>
<DropdownMenu.RadioGroup bind:value>
  <DropdownMenu.GroupHeading>Favorite number</DropdownMenu.GroupHeading>
  {#each values as value}
    <DropdownMenu.RadioItem {value}>
      {#snippet children({ checked })}
        {#if checked}
          ✅
        {/if}
        {value}
      {/snippet}
    </DropdownMenu.RadioItem>
  {/each}
</DropdownMenu.RadioGroup>

value 상태는 메뉴가 열리고 닫히는 사이에 유지되지 않아요. 상태를 유지하려면 $state 변수에 저장하고 value prop으로 전달해야 해요.

체크박스 항목 (Checkbox Items)

DropdownMenu.CheckboxItem 컴포넌트로 menuitemcheckbox 요소를 만들어 메뉴 항목에 체크박스 기능을 더할 수 있어요.

<script lang="ts">
  import { DropdownMenu } from "bits-ui";
  let notifications = $state(true);
</script>
<DropdownMenu.CheckboxItem bind:checked={notifications}>
  {#snippet children({ checked, indeterminate })}
    {#if indeterminate}
      -
    {:else if checked}
      ✅
    {/if}
    Notifications
  {/snippet}
</DropdownMenu.CheckboxItem>

checked 상태는 메뉴가 열리고 닫히는 사이에 유지되지 않아요. 상태를 유지하려면 $state 변수에 저장하고 checked prop으로 전달해야 해요.

체크박스 그룹 (Checkbox Groups)

DropdownMenu.CheckboxGroup 컴포넌트로 DropdownMenu.CheckboxItem 컴포넌트 세트를 감싸면 메뉴 안에 체크박스 그룹을 만들 수 있어요. 이때 value prop은 선택된 값들의 배열이 돼요.

<script lang="ts">
  import { DropdownMenu } from "bits-ui";
  let colors = $state<string[]>([]);
</script>
<DropdownMenu.CheckboxGroup bind:value={colors}>
  <DropdownMenu.GroupHeading>Favorite color</DropdownMenu.GroupHeading>
  <DropdownMenu.CheckboxItem value="red">
    {#snippet children({ checked })}
      {#if checked}
        ✅
      {/if}
      Red
    {/snippet}
  </DropdownMenu.CheckboxItem>
  <DropdownMenu.CheckboxItem value="blue">
    {#snippet children({ checked })}
      {#if checked}
        ✅
      {/if}
      Blue
    {/snippet}
  </DropdownMenu.CheckboxItem>
  <DropdownMenu.CheckboxItem value="green">
    {#snippet children({ checked })}
      {#if checked}
        ✅
      {/if}
      Green
    {/snippet}
  </DropdownMenu.CheckboxItem>
</DropdownMenu.CheckboxGroup>

value 상태는 메뉴가 열리고 닫히는 사이에 유지되지 않아요. 상태를 유지하려면 $state 변수에 저장하고 value prop으로 전달해야 해요.

중첩 메뉴 (Nested Menus)

DropdownMenu.Sub 컴포넌트로 중첩 메뉴를 만들어 복잡한 메뉴 구조를 구성할 수 있어요.

아래 예시는 라디오 그룹, 체크박스 그룹, 여러 중첩 서브메뉴가 섞인 더 깊은 계층을 보여 줘요 (프로젝트 트래커에서 이슈를 필터링하는 것과 비슷해요).

<script lang="ts">
  import { DropdownMenu } from "bits-ui";
  import CaretRight from "phosphor-svelte/lib/CaretRight";
  import Check from "phosphor-svelte/lib/Check";
  import FunnelSimple from "phosphor-svelte/lib/FunnelSimple";
  let selectedStatus = $state("in-progress");
  let selectedPriority = $state("p2");
  let selectedType = $state("feature");
  let selectedLabel = $state("customer-facing");
  let digestPrefs = $state<string[]>(["assignee", "mentions"]);
  const statusItems = [
    { value: "icebox", label: "Icebox" },
    { value: "backlog", label: "Backlog" },
    { value: "todo", label: "Todo" },
    { value: "in-progress", label: "In progress" },
    { value: "done", label: "Done" }
  ] as const;
  const priorityItems = [
    { value: "p0", label: "P0 - Critical" },
    { value: "p1", label: "P1 - High" },
    { value: "p2", label: "P2 - Medium" },
    { value: "p3", label: "P3 - Low" }
  ] as const;
  const typeItems = [
    { value: "bug", label: "Bug" },
    { value: "feature", label: "Feature" },
    { value: "improvement", label: "Improvement" },
    { value: "docs", label: "Docs" }
  ] as const;
  const labelItems = [
    { value: "customer-facing", label: "Customer-facing" },
    { value: "internal-tooling", label: "Internal tooling" },
    { value: "technical-debt", label: "Technical debt" },
    { value: "compliance", label: "Compliance" },
    { value: "platform", label: "Platform" }
  ] as const;
  const digestItems = [
    { value: "assignee", label: "Assignee changes" },
    { value: "comments", label: "New comments" },
    { value: "mentions", label: "@mentions" }
  ] as const;
  const contentClass =
    "border-muted bg-background shadow-popover outline-hidden focus-visible:outline-hidden w-[250px] rounded-xl border px-1 py-1.5";
  const subContentClass =
    "border-muted bg-background shadow-popover outline-hidden focus-visible:outline-hidden z-100 w-[230px] rounded-xl border px-1 py-1.5";
  const itemClass =
    "rounded-button data-highlighted:bg-muted ring-0! ring-transparent! flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none";
  const subTriggerClass =
    "rounded-button data-highlighted:bg-muted data-[state=open]:bg-muted ring-0! ring-transparent! flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none";
</script>
{#snippet radioCheckedIndicator(checked: boolean)}
  {#if checked}
    <svg
      class="text-foreground-alt ml-auto size-4 shrink-0"
      viewBox="0 0 16 16"
      aria-hidden="true"
    >
      <circle cx="8" cy="8" r="4" fill="currentColor" />
    </svg>
  {/if}
{/snippet}
<DropdownMenu.Root>
  <DropdownMenu.Trigger
    class="border-input text-foreground shadow-btn hover:bg-muted inline-flex h-10 select-none items-center justify-center rounded-full border px-4 text-sm font-medium active:scale-[0.98]"
  >
    <FunnelSimple class="size-5" />
    <span class="ml-1.5">Filter issue</span>
  </DropdownMenu.Trigger>
  <DropdownMenu.Portal>
    <DropdownMenu.Content class={contentClass} sideOffset={8}>
      <DropdownMenu.Item class={itemClass} disabled
        >Search issues…</DropdownMenu.Item
      >
      <DropdownMenu.Sub>
        <DropdownMenu.SubTrigger class={subTriggerClass}>
          Status
          <CaretRight class="text-foreground-alt ml-auto size-4" />
        </DropdownMenu.SubTrigger>
        <DropdownMenu.Portal>
          <DropdownMenu.SubContent class={subContentClass} sideOffset={10}>
            <DropdownMenu.RadioGroup bind:value={selectedStatus}>
              {#each statusItems as item (item.value)}
                <DropdownMenu.RadioItem value={item.value} class={itemClass}>
                  {#snippet children({ checked })}
                    {item.label}
                    {@render radioCheckedIndicator(checked)}
                  {/snippet}
                </DropdownMenu.RadioItem>
              {/each}
            </DropdownMenu.RadioGroup>
          </DropdownMenu.SubContent>
        </DropdownMenu.Portal>
      </DropdownMenu.Sub>
      <DropdownMenu.Sub>
        <DropdownMenu.SubTrigger class={subTriggerClass}>
          Issue properties
          <CaretRight class="text-foreground-alt ml-auto size-4" />
        </DropdownMenu.SubTrigger>
        <DropdownMenu.Portal>
          <DropdownMenu.SubContent class={subContentClass} sideOffset={10}>
            <DropdownMenu.Sub>
              <DropdownMenu.SubTrigger class={subTriggerClass}>
                Priority
                <CaretRight class="text-foreground-alt ml-auto size-4" />
              </DropdownMenu.SubTrigger>
              <DropdownMenu.Portal>
                <DropdownMenu.SubContent
                  class={subContentClass}
                  sideOffset={10}
                >
                  <DropdownMenu.RadioGroup bind:value={selectedPriority}>
                    {#each priorityItems as item (item.value)}
                      <DropdownMenu.RadioItem
                        value={item.value}
                        class={itemClass}
                      >
                        {#snippet children({ checked })}
                          {item.label}
                          {@render radioCheckedIndicator(checked)}
                        {/snippet}
                      </DropdownMenu.RadioItem>
                    {/each}
                  </DropdownMenu.RadioGroup>
                </DropdownMenu.SubContent>
              </DropdownMenu.Portal>
            </DropdownMenu.Sub>
            <DropdownMenu.Sub>
              <DropdownMenu.SubTrigger class={subTriggerClass}>
                Type
                <CaretRight class="text-foreground-alt ml-auto size-4" />
              </DropdownMenu.SubTrigger>
              <DropdownMenu.Portal>
                <DropdownMenu.SubContent
                  class={subContentClass}
                  sideOffset={10}
                >
                  <DropdownMenu.RadioGroup bind:value={selectedType}>
                    {#each typeItems as item (item.value)}
                      <DropdownMenu.RadioItem
                        value={item.value}
                        class={itemClass}
                      >
                        {#snippet children({ checked })}
                          {item.label}
                          {@render radioCheckedIndicator(checked)}
                        {/snippet}
                      </DropdownMenu.RadioItem>
                    {/each}
                  </DropdownMenu.RadioGroup>
                </DropdownMenu.SubContent>
              </DropdownMenu.Portal>
            </DropdownMenu.Sub>
            <DropdownMenu.Separator class="bg-muted -mx-1 my-1 block h-px" />
            <DropdownMenu.CheckboxGroup bind:value={digestPrefs}>
              <DropdownMenu.GroupHeading
                class="text-muted-foreground px-3 pb-2 pt-3 text-xs font-medium"
              >
                Email digest
              </DropdownMenu.GroupHeading>
              {#each digestItems as item (item.value)}
                <DropdownMenu.CheckboxItem value={item.value} class={itemClass}>
                  {#snippet children({ checked })}
                    <span>{item.label}</span>
                    {#if checked}
                      <Check
                        class="text-foreground-alt ml-auto size-4 shrink-0"
                      />
                    {/if}
                  {/snippet}
                </DropdownMenu.CheckboxItem>
              {/each}
            </DropdownMenu.CheckboxGroup>
            <DropdownMenu.Sub>
              <DropdownMenu.SubTrigger class={subTriggerClass}>
                Labels
                <CaretRight class="text-foreground-alt ml-auto size-4" />
              </DropdownMenu.SubTrigger>
              <DropdownMenu.Portal>
                <DropdownMenu.SubContent
                  class={subContentClass}
                  sideOffset={10}
                >
                  <DropdownMenu.RadioGroup bind:value={selectedLabel}>
                    {#each labelItems as item (item.value)}
                      <DropdownMenu.RadioItem
                        value={item.value}
                        class={itemClass}
                      >
                        {#snippet children({ checked })}
                          {item.label}
                          {@render radioCheckedIndicator(checked)}
                        {/snippet}
                      </DropdownMenu.RadioItem>
                    {/each}
                  </DropdownMenu.RadioGroup>
                  <DropdownMenu.Sub>
                    <DropdownMenu.SubTrigger class={subTriggerClass}>
                      Product area
                      <CaretRight class="text-foreground-alt ml-auto size-4" />
                    </DropdownMenu.SubTrigger>
                    <DropdownMenu.Portal>
                      <DropdownMenu.SubContent
                        class={subContentClass}
                        sideOffset={10}
                      >
                        <DropdownMenu.Item class={itemClass}
                          >Web app</DropdownMenu.Item
                        >
                        <DropdownMenu.Item class={itemClass}
                          >Mobile</DropdownMenu.Item
                        >
                        <DropdownMenu.Item class={itemClass}
                          >CLI</DropdownMenu.Item
                        >
                        <DropdownMenu.Item class={itemClass}
                          >Marketing site</DropdownMenu.Item
                        >
                      </DropdownMenu.SubContent>
                    </DropdownMenu.Portal>
                  </DropdownMenu.Sub>
                </DropdownMenu.SubContent>
              </DropdownMenu.Portal>
            </DropdownMenu.Sub>
          </DropdownMenu.SubContent>
        </DropdownMenu.Portal>
      </DropdownMenu.Sub>
    </DropdownMenu.Content>
  </DropdownMenu.Portal>
</DropdownMenu.Root>
<script lang="ts">
  import { DropdownMenu } from "bits-ui";
</script>
<DropdownMenu.Content>
  <DropdownMenu.Item>Item 1</DropdownMenu.Item>
  <DropdownMenu.Item>Item 2</DropdownMenu.Item>
  <DropdownMenu.Sub>
    <DropdownMenu.SubTrigger>Open Sub Menu</DropdownMenu.SubTrigger>
    <DropdownMenu.SubContent>
      <DropdownMenu.Item>Sub Item 1</DropdownMenu.Item>
      <DropdownMenu.Item>Sub Item 2</DropdownMenu.Item>
    </DropdownMenu.SubContent>
  </DropdownMenu.Sub>
</DropdownMenu.Content>

Svelte Transitions

forceMount prop과 child 스니펫을 함께 사용하면 DropdownMenu.Content 컴포넌트를 강제로 마운트해서 Svelte Transitions이나 더 많은 제어가 필요한 다른 애니메이션 라이브러리를 쓸 수 있어요.

<script lang="ts">
  import { DropdownMenu } from "bits-ui";
  import { fly } from "svelte/transition";
</script>
<DropdownMenu.Content forceMount>
  {#snippet child({ wrapperProps, props, open })}
    {#if open}
      <div {...wrapperProps}>
        <div {...props} transition:fly>
          <DropdownMenu.Item>Item 1</DropdownMenu.Item>
          <DropdownMenu.Item>Item 2</DropdownMenu.Item>
        </div>
      </div>
    {/if}
  {/snippet}
</DropdownMenu.Content>

물론 이 문법이 가장 깔끔한 건 아니에요. 그래서 이 방법을 쓸 생각이라면 이 로직을 처리하는 나만의 재사용 가능한 콘텐츠 컴포넌트를 만드는 걸 권장해요. Bits UI 컴포넌트에서 트랜지션을 사용하는 방법에 대한 자세한 내용은 Transitions 문서를 확인하세요.

<script lang="ts">
  import { Avatar, DropdownMenu } from "bits-ui";
  import Cardholder from "phosphor-svelte/lib/Cardholder";
  import CaretRight from "phosphor-svelte/lib/CaretRight";
  import DotsThree from "phosphor-svelte/lib/DotsThree";
  import GearSix from "phosphor-svelte/lib/GearSix";
  import UserCircle from "phosphor-svelte/lib/UserCircle";
  import UserCirclePlus from "phosphor-svelte/lib/UserCirclePlus";
  import Bell from "phosphor-svelte/lib/Bell";
  import Check from "phosphor-svelte/lib/Check";
  import DotOutline from "phosphor-svelte/lib/DotOutline";
  import { fly } from "svelte/transition";
  let notifications = $state<boolean>(false);
  let invited = $state("");
</script>
<DropdownMenu.Root>
  <DropdownMenu.Trigger
    class="border-input shadow-btn hover:bg-muted inline-flex h-10 w-10 select-none items-center justify-center rounded-full border text-sm font-medium active:scale-[0.98]"
  >
    <DotsThree class="text-foreground h-6 w-6" />
  </DropdownMenu.Trigger>
  <DropdownMenu.Portal>
    <DropdownMenu.Content
      class="border-muted bg-background shadow-popover w-[229px] rounded-xl border px-1 py-1.5 focus-visible:outline-none"
      sideOffset={8}
      forceMount
    >
      {#snippet child({ wrapperProps, props, open })}
        {#if open}
          <div {...wrapperProps}>
            <div {...props} transition:fly={{ duration: 300 }}>
              <DropdownMenu.Item
                class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
              >
                <div class="flex items-center">
                  <UserCircle class="text-foreground-alt mr-2 size-5" />
                  Profile
                </div>
                <div class="ml-auto flex items-center gap-px">
                  <kbd
                    class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-xs"
                  >
                    ⌘
                  </kbd>
                  <kbd
                    class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-[10px]"
                  >
                    P
                  </kbd>
                </div>
              </DropdownMenu.Item>
              <DropdownMenu.Item
                class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
              >
                <div class="flex items-center">
                  <Cardholder class="text-foreground-alt mr-2 size-5" />
                  Billing
                </div>
                <div class="ml-auto flex items-center gap-px">
                  <kbd
                    class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-xs"
                  >
                    ⌘
                  </kbd>
                  <kbd
                    class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-[10px]"
                  >
                    B
                  </kbd>
                </div>
              </DropdownMenu.Item>
              <DropdownMenu.Item
                class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
              >
                <div class="flex items-center">
                  <GearSix class="text-foreground-alt mr-2 size-5" />
                  Settings
                </div>
                <div class="ml-auto flex items-center gap-px">
                  <kbd
                    class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-xs"
                  >
                    ⌘
                  </kbd>
                  <kbd
                    class="rounded-button border-dark-10 bg-background-alt text-muted-foreground shadow-kbd inline-flex size-5 items-center justify-center border text-[10px]"
                  >
                    S
                  </kbd>
                </div>
              </DropdownMenu.Item>
              <DropdownMenu.CheckboxItem
                bind:checked={notifications}
                class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
              >
                {#snippet children({ checked })}
                  <div class="flex items-center pr-4">
                    <Bell class="text-foreground-alt mr-2 size-5" />
                    Notifications
                  </div>
                  <div class="ml-auto flex items-center gap-px">
                    {#if checked}
                      <Check class="size-4" />
                    {/if}
                  </div>
                {/snippet}
              </DropdownMenu.CheckboxItem>
              <DropdownMenu.Sub>
                <DropdownMenu.SubTrigger
                  class="rounded-button data-highlighted:bg-muted data-[state=open]:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
                >
                  <div class="flex items-center">
                    <UserCirclePlus class="text-foreground-alt mr-2 size-5" />
                    Workspace
                  </div>
                  <div class="ml-auto flex items-center gap-px">
                    <CaretRight class="text-foreground-alt size-5" />
                  </div>
                </DropdownMenu.SubTrigger>
                <DropdownMenu.SubContent
                  class="border-muted bg-background shadow-popover w-[209px] rounded-xl border px-1 py-1.5 focus-visible:outline-none"
                  sideOffset={10}
                >
                  <DropdownMenu.RadioGroup bind:value={invited}>
                    <DropdownMenu.RadioItem
                      value="huntabyte"
                      class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
                    >
                      {#snippet children({ checked })}
                        <Avatar.Root
                          class="border-foreground/50 relative mr-3 flex size-5 shrink-0 overflow-hidden rounded-full border"
                        >
                          <Avatar.Image
                            src="https://github.com/huntabyte.png"
                            alt="@huntabyte"
                            class="aspect-square h-full w-full"
                          />
                          <Avatar.Fallback
                            class="bg-muted text-xxs flex h-full w-full items-center justify-center rounded-full"
                            >HJ</Avatar.Fallback
                          >
                        </Avatar.Root>
                        @huntabyte
                        {#if checked}
                          <DotOutline class="ml-auto size-4" />
                        {/if}
                      {/snippet}
                    </DropdownMenu.RadioItem>
                    <DropdownMenu.RadioItem
                      value="pavel"
                      class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
                    >
                      {#snippet children({ checked })}
                        <Avatar.Root
                          class="border-foreground/50 relative mr-3 flex size-5 shrink-0 overflow-hidden rounded-full border"
                        >
                          <Avatar.Image
                            src="https://github.com/pavelstianko.png"
                            alt="@pavel_stianko"
                            class="aspect-square h-full w-full"
                          />
                          <Avatar.Fallback
                            class="bg-muted flex h-full w-full items-center justify-center rounded-full text-xs"
                            >PS</Avatar.Fallback
                          >
                        </Avatar.Root>
                        @pavel_stianko
                        {#if checked}
                          <DotOutline class="ml-auto size-4" />
                        {/if}
                      {/snippet}
                    </DropdownMenu.RadioItem>
                    <DropdownMenu.RadioItem
                      value="cokakoala"
                      class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
                    >
                      {#snippet children({ checked })}
                        <Avatar.Root
                          class="border-foreground/50 relative mr-3 flex size-5 shrink-0 overflow-hidden rounded-full border"
                        >
                          <Avatar.Image
                            src="https://github.com/adriangonz97.png"
                            alt="@cokakoala_"
                            class="aspect-square h-full w-full"
                          />
                          <Avatar.Fallback
                            class="bg-muted flex h-full w-full items-center justify-center rounded-full text-xs"
                            >CK</Avatar.Fallback
                          >
                        </Avatar.Root>
                        @cokakoala_
                        {#if checked}
                          <DotOutline class="ml-auto size-4" />
                        {/if}
                      {/snippet}
                    </DropdownMenu.RadioItem>
                    <DropdownMenu.RadioItem
                      value="tglide"
                      class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
                    >
                      {#snippet children({ checked })}
                        <Avatar.Root
                          class="border-foreground/50 relative mr-3 flex size-5 shrink-0 overflow-hidden rounded-full border"
                        >
                          <Avatar.Image
                            src="https://github.com/tglide.png"
                            alt="@tglide"
                            class="aspect-square h-full w-full"
                          />
                          <Avatar.Fallback
                            class="bg-muted flex h-full w-full items-center justify-center rounded-full text-xs"
                          >
                            TL
                          </Avatar.Fallback>
                        </Avatar.Root>
                        @thomasglopes
                        {#if checked}
                          <DotOutline class="ml-auto size-4" />
                        {/if}
                      {/snippet}
                    </DropdownMenu.RadioItem>
                  </DropdownMenu.RadioGroup>
                </DropdownMenu.SubContent>
              </DropdownMenu.Sub>
            </div>
          </div>
        {/if}
      {/snippet}
    </DropdownMenu.Content>
  </DropdownMenu.Portal>
</DropdownMenu.Root>

커스텀 앵커 (Custom Anchor)

기본적으로 DropdownMenu.Content는 콘텐츠가 배치될 위치를 결정하는 DropdownMenu.Trigger 컴포넌트에 고정돼요.

콘텐츠를 다른 요소에 고정하고 싶다면 DropdownMenu.Content 컴포넌트의 customAnchor prop에 선택자 string이나 HTMLElement를 전달하면 돼요.

<script lang="ts">
  import { DropdownMenu } from "bits-ui";
  let customAnchor = $state<HTMLElement>(null!);
</script>
<div bind:this={customAnchor}></div>
<DropdownMenu.Root>
  <DropdownMenu.Trigger />
  <DropdownMenu.Content {customAnchor}>
    <!-- ... -->
  </DropdownMenu.Content>
</DropdownMenu.Root>

API Reference

드롭다운 메뉴의 상태를 관리하고 범위를 지정하는 루트 컴포넌트예요.

Property Type Description Details
open $bindable boolean The open state of the menu.Default: false
onOpenChange function - (open: boolean) => void A callback function called when the open state changes.Default:  —— undefined
onOpenChangeComplete function - (open: boolean) => void A callback function called after the open state changes and all animations have completed.Default:  —— undefined
dir enum - 'ltr' | 'rtl' The reading direction of the app.Default: 'ltr'
children Snippet The children content to render.Default:  —— undefined

드롭다운 메뉴를 토글하는 버튼 요소예요.

Property Type Description Details
disabled boolean Whether or not the menu trigger is disabled.Default: false
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-state enum - 'open' | 'closed' The open state of the menu or submenu the element controls or belongs to.
data-dropdown-menu-trigger '' Present on the trigger element.

드롭다운 메뉴의 콘텐츠를 body나 커스텀 대상(제공된 경우)으로 포털로 렌더링하는 컴포넌트예요.

Property Type Description Details
to union - Element | string Where to render the content when it is open. Defaults to the body.Default: document.body
disabled boolean Whether the portal is disabled or not. When disabled, the content will be rendered in its original DOM location.Default: false
children Snippet The children content to render.Default:  —— undefined

드롭다운 메뉴가 열려 있을 때 표시되는 콘텐츠예요.

Property Type Description Details
side enum - 'top' | 'bottom' | 'left' | 'right' The preferred side of the anchor to render the floating element against when open. Will be reversed when collisions occur.Default: 'bottom'
sideOffset number The distance in pixels from the anchor to the floating element.Default: 0
align enum - 'start' | 'center' | 'end' The preferred alignment of the anchor to render the floating element against when open. This may change when collisions occur.Default: 'start'
alignOffset number The distance in pixels from the anchor to the floating element.Default: 0
arrowPadding number The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision.Default: 0
avoidCollisions boolean When true, overrides the side and align options to prevent collisions with the boundary edges.Default: true
collisionBoundary union - Element | null A boundary element or array of elements to check for collisions against.Default:  —— undefined
collisionPadding union - number | Partial<Record<Side, number>> The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision.Default: 0
sticky enum - 'partial' | 'always' The sticky behavior on the align axis. 'partial' will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst 'always' will keep the content in the boundary regardless.Default: 'partial'
hideWhenDetached boolean When true, hides the content when it is detached from the DOM. This is useful for when you want to hide the content when the user scrolls away.Default: true
updatePositionStrategy enum - 'optimized' | 'always' The strategy to use when updating the position of the content. When 'optimized' the content will only be repositioned when the trigger is in the viewport. When 'always' the content will be repositioned whenever the position changes.Default: 'optimized'
strategy enum - 'fixed' | 'absolute' The positioning strategy to use for the floating element. When 'fixed' the element will be positioned relative to the viewport. When 'absolute' the element will be positioned relative to the nearest positioned ancestor.Default: 'fixed'
preventScroll boolean When true, prevents the body from scrolling when the content is open. This is useful when you want to use the content as a modal.Default: true
customAnchor union - string | HTMLElement | Measurable | null Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger.Default: null
onEscapeKeydown function - (event: KeyboardEvent) => void Callback fired when an escape keydown event occurs in the floating content. You can call event.preventDefault() to prevent the default behavior of handling the escape keydown event.Default:  —— undefined
escapeKeydownBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an escape keydown event occurs in the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onInteractOutside function - (event: PointerEvent) => void Callback fired when an outside interaction event occurs, which is a pointerdown event. You can call event.preventDefault() to prevent the default behavior of handling the outside interaction.Default:  —— undefined
onFocusOutside function - (event: FocusEvent) => void Callback fired when focus leaves the dismissible layer. You can call event.preventDefault() to prevent the default behavior on focus leaving the layer.Default:  —— undefined
interactOutsideBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an interaction occurs outside of the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onOpenAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is opened. Can be prevented.Default:  —— undefined
onCloseAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is closed. Can be prevented.Default:  —— undefined
trapFocus boolean Whether or not to trap the focus within the content when open.Default: true
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
preventOverflowTextSelection boolean When true, prevents the text selection from overflowing the bounds of the element.Default: true
dir enum - 'ltr' | 'rtl' The reading direction of the app.Default: 'ltr'
loop boolean Whether or not to loop through the menu items in when navigating with the keyboard.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 ChildSnippetProps = { /** * Props for the positioning wrapper * Do not style this element - * styling should be applied to the content element */ wrapperProps: Record<string, unknown>; /** * Props for your content element * Apply your custom styles here */ props: Record<string, unknown>; /** * Content visibility state * Use this for conditional rendering with * Svelte transitions */ open: boolean; }; 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' The open state of the menu or submenu the element controls or belongs to.
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-dropdown-menu-content '' Present on the content element.
CSS Variable Description Details
--bits-dropdown-menu-content-transform-origin The transform origin of the content element.
--bits-dropdown-menu-content-available-width The available width of the content element.
--bits-dropdown-menu-content-available-height The available height of the content element.
--bits-dropdown-menu-anchor-width The width of the anchor element.
--bits-dropdown-menu-anchor-height The height of the anchor element.

드롭다운 메뉴가 열려 있을 때 표시되는 콘텐츠예요. (정적/Floating UI 미사용)

Property Type Description Details
onEscapeKeydown function - (event: KeyboardEvent) => void Callback fired when an escape keydown event occurs in the floating content. You can call event.preventDefault() to prevent the default behavior of handling the escape keydown event.Default:  —— undefined
escapeKeydownBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an escape keydown event occurs in the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onInteractOutside function - (event: PointerEvent) => void Callback fired when an outside interaction event occurs, which is a pointerdown event. You can call event.preventDefault() to prevent the default behavior of handling the outside interaction.Default:  —— undefined
onFocusOutside function - (event: FocusEvent) => void Callback fired when focus leaves the dismissible layer. You can call event.preventDefault() to prevent the default behavior on focus leaving the layer.Default:  —— undefined
interactOutsideBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an interaction occurs outside of the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onOpenAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is opened. Can be prevented.Default:  —— undefined
onCloseAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is closed. Can be prevented.Default:  —— undefined
trapFocus boolean Whether or not to trap the focus within the content when open.Default: true
preventScroll boolean When true, prevents the body from scrolling when the content is open. This is useful when you want to use the content as a modal.Default: true
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
preventOverflowTextSelection boolean When true, prevents the text selection from overflowing the bounds of the element.Default: true
dir enum - 'ltr' | 'rtl' The reading direction of the app.Default: 'ltr'
loop boolean Whether or not to loop through the menu items in when navigating with the keyboard.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 ChildSnippetProps = { 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-state enum - 'open' | 'closed' The open state of the menu or submenu the element controls or belongs to.
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-dropdown-menu-content '' Present on the content element.

드롭다운 메뉴 안의 메뉴 항목이에요.

Property Type Description Details
disabled boolean Whether or not the menu item is disabled.Default: false
textValue string The text value of the checkbox menu item. This is used for typeahead.Default:  —— undefined
onSelect function - () => void A callback that is fired when the menu item is selected.Default:  —— undefined
closeOnSelect boolean Whether or not the menu item should close when selected.Default: true
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 vertical The orientation of the menu.
data-highlighted '' Present when the menu item is highlighted.
data-disabled '' Present when the menu item is disabled.
data-dropdown-menu-item '' Present on the item element.

여러 항목을 동시에 체크할 수 있는 체크박스 메뉴 항목 그룹이에요.

Property Type Description Details
value $bindable string[] The value of the group. This is an array of the values of the checked checkboxes within the group.Default: []
onValueChange function - (value: string[]) => void A callback that is fired when the checkbox group's value state changes.Default:  —— undefined
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-dropdown-menu-checkbox-group '' Present on the checkbox group element.

체크박스처럼 제어하고 토글할 수 있는 메뉴 항목이에요.

Property Type Description Details
disabled boolean Whether or not the checkbox menu item is disabled. Disabled items cannot be interacted with and are skipped when navigating with the keyboard.Default: false
checked $bindable boolean The checked state of the checkbox.Default: false
onCheckedChange function - (checked: boolean) => void A callback that is fired when the checked state changes.Default:  —— undefined
indeterminate $bindable boolean The indeterminate state of the checkbox.Default: false
onIndeterminateChange function - (indeterminate: boolean) => void A callback that is fired when the indeterminate state changes.Default:  —— undefined
value string The value of the checkbox item when used in a *Menu.CheckboxGroup.Default:  —— undefined
textValue string The text value of the checkbox menu item. This is used for typeahead.Default:  —— undefined
onSelect function - () => void A callback that is fired when the menu item is selected.Default:  —— undefined
closeOnSelect boolean Whether or not the menu item should close when selected.Default: true
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 - type ChildrenSnippetProps = { checked: boolean; indeterminate: boolean; }; The children content to render.Default:  —— undefined
child Snippet - type ChildSnippetProps = { props: Record<string, unknown>; checked: boolean; indeterminate: boolean; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-orientation vertical The orientation of the menu.
data-highlighted '' Present when the menu item is highlighted.
data-disabled '' Present when the menu item is disabled.
data-state enum - 'checked' | 'unchecked' | 'indeterminate' The checkbox menu item's checked state.
data-dropdown-menu-checkbox-item '' Present on the checkbox item element.

한 번에 하나만 체크할 수 있는 라디오 메뉴 항목 그룹이에요.

Property Type Description Details
value $bindable string The value of the currently checked radio menu item.Default:  —— undefined
onValueChange function - (value: string) => void A callback that is fired when the radio group's value changes.Default:  —— undefined
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-dropdown-menu-radio-group '' Present on the radio group element.

라디오 버튼처럼 제어하고 토글할 수 있는 메뉴 항목이에요. RadioGroup의 자식이어야 해요.

Property Type Description Details
value required string The value of the radio item. When checked, the parent RadioGroup's value will be set to this value.Default:  —— undefined
disabled boolean Whether or not the radio menu item is disabled. Disabled items cannot be interacted with and are skipped when navigating with the keyboard.Default: false
textValue string The text value of the checkbox menu item. This is used for typeahead.Default:  —— undefined
onSelect function - () => void A callback that is fired when the menu item is selected.Default:  —— undefined
closeOnSelect boolean Whether or not the menu item should close when selected.Default: true
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 - type ChildrenSnippetProps = { checked: boolean; }; The children content to render.Default:  —— undefined
child Snippet - type ChildSnippetProps = { props: Record<string, unknown>; checked: boolean; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-orientation vertical The orientation of the menu.
data-highlighted '' Present when the menu item is highlighted.
data-disabled '' Present when the menu item is disabled.
data-state enum - 'checked' | 'unchecked' The radio menu item's checked state.
data-value '' The value of the radio item.
data-dropdown-menu-radio-item '' Present on the radio item element.

메뉴 항목을 시각적으로 구분하는 가로선이에요.

Property Type Description Details
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 vertical The orientation of the separator.
data-menu-separator '' Present on the separator element.
data-dropdown-menu-separator '' Present on the separator element.

드롭다운 메뉴의 앵커/트리거 지점을 가리키는 선택적 화살표예요.

Property Type Description Details
width number The width of the arrow in pixels.Default: 8
height number The height of the arrow in pixels.Default: 8
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' The open state of the menu or submenu the element controls or belongs to.
data-dropdown-menu-arrow '' Present on the arrow element.

메뉴 항목들의 그룹이에요. aria-label을 전달하거나 자식으로 DropdownMenu.GroupHeading 컴포넌트를 두어 그룹에 라벨을 붙여야 해요.

Property Type Description Details
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-dropdown-menu-group '' Present on the group element.

키보드로 탐색할 때 건너뛰는 그룹 헤딩이에요. 메뉴 항목 그룹에 대한 설명을 제공하며, DropdownMenu.Group이나 DropdownMenu.RadioGroup 컴포넌트의 자식이어야 해요.

Property Type Description Details
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-dropdown-menu-group-heading '' Present on the group heading element.

부모 드롭다운 메뉴에 속한 서브메뉴예요. 서브메뉴의 상태 관리를 담당해요.

Property Type Description Details
open $bindable boolean The open state of the submenu.Default: false
onOpenChange function - (open: boolean) => void A callback function called when the open state changes.Default:  —— undefined
onOpenChangeComplete function - (open: boolean) => void A callback function called after the open state changes and all animations have completed.Default:  —— undefined
children Snippet The children content to render.Default:  —— undefined

누르거나 호버하면 자신이 자식으로 속한 서브메뉴를 여는 메뉴 항목이에요.

Property Type Description Details
disabled boolean Whether or not the submenu trigger is disabled.Default: false
openDelay number The amount of time in ms from when the mouse enters the subtrigger until the submenu opens.Default: 0
textValue string The text value of the checkbox menu item. This is used for typeahead.Default:  —— undefined
onSelect function - () => void A callback that is fired when the menu item is selected.Default:  —— undefined
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 vertical The orientation of the menu.
data-highlighted '' Present when the menu item is highlighted.
data-disabled '' Present when the menu item is disabled.
data-state enum - 'open' | 'closed' The open state of the menu or submenu the element controls or belongs to.
data-dropdown-menu-sub-trigger '' Present on the submenu trigger element.

부모 서브메뉴가 열려 있을 때 표시되는 서브메뉴 콘텐츠예요.

Property Type Description Details
side enum - 'top' | 'bottom' | 'left' | 'right' The preferred side of the anchor to render the floating element against when open. Will be reversed when collisions occur.Default: 'bottom'
sideOffset number The distance in pixels from the anchor to the floating element.Default: 0
align enum - 'start' | 'center' | 'end' The preferred alignment of the anchor to render the floating element against when open. This may change when collisions occur.Default: 'start'
alignOffset number The distance in pixels from the anchor to the floating element.Default: 0
arrowPadding number The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision.Default: 0
avoidCollisions boolean When true, overrides the side and align options to prevent collisions with the boundary edges.Default: true
collisionBoundary union - Element | null A boundary element or array of elements to check for collisions against.Default:  —— undefined
collisionPadding union - number | Partial<Record<Side, number>> The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision.Default: 0
sticky enum - 'partial' | 'always' The sticky behavior on the align axis. 'partial' will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst 'always' will keep the content in the boundary regardless.Default: 'partial'
hideWhenDetached boolean When true, hides the content when it is detached from the DOM. This is useful for when you want to hide the content when the user scrolls away.Default: true
updatePositionStrategy enum - 'optimized' | 'always' The strategy to use when updating the position of the content. When 'optimized' the content will only be repositioned when the trigger is in the viewport. When 'always' the content will be repositioned whenever the position changes.Default: 'optimized'
strategy enum - 'fixed' | 'absolute' The positioning strategy to use for the floating element. When 'fixed' the element will be positioned relative to the viewport. When 'absolute' the element will be positioned relative to the nearest positioned ancestor.Default: 'fixed'
preventScroll boolean When true, prevents the body from scrolling when the content is open. This is useful when you want to use the content as a modal.Default: true
customAnchor union - string | HTMLElement | Measurable | null Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger.Default: null
onEscapeKeydown function - (event: KeyboardEvent) => void Callback fired when an escape keydown event occurs in the floating content. You can call event.preventDefault() to prevent the default behavior of handling the escape keydown event.Default:  —— undefined
escapeKeydownBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an escape keydown event occurs in the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onInteractOutside function - (event: PointerEvent) => void Callback fired when an outside interaction event occurs, which is a pointerdown event. You can call event.preventDefault() to prevent the default behavior of handling the outside interaction.Default:  —— undefined
onFocusOutside function - (event: FocusEvent) => void Callback fired when focus leaves the dismissible layer. You can call event.preventDefault() to prevent the default behavior on focus leaving the layer.Default:  —— undefined
interactOutsideBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an interaction occurs outside of the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onOpenAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is opened. Can be prevented.Default:  —— undefined
onCloseAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is closed. Can be prevented.Default:  —— undefined
trapFocus boolean Whether or not to trap the focus within the content when open.Default: true
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
preventOverflowTextSelection boolean When true, prevents the text selection from overflowing the bounds of the element.Default: true
dir enum - 'ltr' | 'rtl' The reading direction of the app.Default: 'ltr'
loop boolean Whether or not to loop through the menu items in when navigating with the keyboard.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 ChildSnippetProps = { /** * Props for the positioning wrapper * Do not style this element - * styling should be applied to the content element */ wrapperProps: Record<string, unknown>; /** * Props for your content element * Apply your custom styles here */ props: Record<string, unknown>; /** * Content visibility state * Use this for conditional rendering with * Svelte transitions */ open: boolean; }; 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' The open state of the menu or submenu the element controls or belongs to.
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-dropdown-menu-sub-content '' Present on the submenu content element.

부모 서브메뉴가 열려 있을 때 표시되는 서브메뉴 콘텐츠예요. (정적/Floating UI 미사용)

Property Type Description Details
onEscapeKeydown function - (event: KeyboardEvent) => void Callback fired when an escape keydown event occurs in the floating content. You can call event.preventDefault() to prevent the default behavior of handling the escape keydown event.Default:  —— undefined
escapeKeydownBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an escape keydown event occurs in the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onInteractOutside function - (event: PointerEvent) => void Callback fired when an outside interaction event occurs, which is a pointerdown event. You can call event.preventDefault() to prevent the default behavior of handling the outside interaction.Default:  —— undefined
onFocusOutside function - (event: FocusEvent) => void Callback fired when focus leaves the dismissible layer. You can call event.preventDefault() to prevent the default behavior on focus leaving the layer.Default:  —— undefined
interactOutsideBehavior enum - 'close' | 'ignore' | 'defer-otherwise-close' | 'defer-otherwise-ignore' The behavior to use when an interaction occurs outside of the floating content. 'close' will close the content immediately. 'ignore' will prevent the content from closing. 'defer-otherwise-close' will defer to the parent element if it exists, otherwise it will close the content. 'defer-otherwise-ignore' will defer to the parent element if it exists, otherwise it will ignore the interaction.Default: 'close'
onOpenAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is opened. Can be prevented.Default:  —— undefined
onCloseAutoFocus function - (event: Event) => void Event handler called when auto-focusing the content as it is closed. Can be prevented.Default:  —— undefined
trapFocus boolean Whether or not to trap the focus within the content when open.Default: true
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
preventOverflowTextSelection boolean When true, prevents the text selection from overflowing the bounds of the element.Default: true
dir enum - 'ltr' | 'rtl' The reading direction of the app.Default: 'ltr'
loop boolean Whether or not to loop through the menu items when reaching the end of the list when using the keyboard.Default: true
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 ChildSnippetProps = { 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-state enum - 'open' | 'closed' The open state of the menu or submenu the element controls or belongs to.
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-dropdown-menu-sub-content '' Present on the submenu content element.

더 알아보기 (Learn more)

Dropdown Menu는 팝오버 방식의 메뉴라서 Popover와 열림 상태·포커스·바깥 상호작용 처리를 공유해요. 서브메뉴나 체크박스·라디오 항목이 필요한 상황이라면 이 컴포넌트의 하위 항목들을 조합해 쓰면 됩니다. 메뉴가 여러 위치에 반복된다면 Menubar나 관련 팝오버 문서도 함께 비교해 보세요.