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

Menubar 문서

원문 보기 위키 갱신

Menubar는 메뉴 모음을 담고 있는 가로 막대 형태의 컴포넌트예요. 상단 내비게이션처럼 여러 메뉴를 한 줄에 배치하고, 각 메뉴를 클릭해 하위 항목을 펼칠 수 있어요.

출처: 문서

본문

<script lang="ts">
  import { Menubar } from "bits-ui";
  import CaretRight from "phosphor-svelte/lib/CaretRight";
  import Cat from "phosphor-svelte/lib/Cat";
  import Check from "phosphor-svelte/lib/Check";
  let selectedView = $state("table");
  let selectedProfile = $state("pavel");
  let grids = $state([
    {
      checked: true,
      label: "Pixel"
    },
    {
      checked: false,
      label: "Layout"
    }
  ]);
  let showConfigs = $state([
    {
      checked: true,
      label: "Show Bookmarks"
    },
    {
      checked: false,
      label: "Show Full URLs"
    }
  ]);
  const profiles = [
    {
      value: "hunter",
      label: "Hunter"
    },
    {
      value: "pavel",
      label: "Pavel"
    },
    {
      value: "adrian",
      label: "Adrian"
    }
  ];
  const views = [
    {
      value: "table",
      label: "Table"
    },
    {
      value: "board",
      label: "Board"
    },
    {
      value: "gallery",
      label: "Gallery"
    }
  ];
</script>
<Menubar.Root
  class="rounded-10px border-dark-10 bg-background-alt shadow-mini flex h-12 items-center gap-1 border px-[3px]"
>
  <div class="px-2.5">
    <Cat class="size-6" />
  </div>
  <Menubar.Menu>
    <Menubar.Trigger
      class="rounded-9px data-highlighted:bg-muted data-[state=open]:bg-muted inline-flex h-10 cursor-default items-center justify-center px-3 text-sm font-medium focus-visible:outline-none"
    >
      File
    </Menubar.Trigger>
    <Menubar.Portal>
      <Menubar.Content
        class="focus-override border-muted bg-background  shadow-popover focus-visible:outline-hidden z-50 w-fit rounded-xl border px-1 py-1.5"
        align="start"
        sideOffset={3}
      >
        {#each grids as grid (grid.label)}
          <Menubar.CheckboxItem
            class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center gap-3 py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
            bind:checked={grid.checked}
          >
            {#snippet children({ checked })}
              {grid.label} grid
              <div class="ml-auto flex items-center">
                {#if checked}
                  {@render SwitchOn()}
                {:else}
                  {@render SwitchOff()}
                {/if}
              </div>
            {/snippet}
          </Menubar.CheckboxItem>
        {/each}
        <Menubar.Separator class="bg-muted my-1 -ml-1 -mr-1 block h-px" />
        <Menubar.RadioGroup bind:value={selectedView}>
          {#each views as view, i (view.label + i)}
            <Menubar.RadioItem
              value={view.value}
              class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center gap-2 py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
            >
              {#snippet children({ checked })}
                {view.label}
                <div class="ml-auto size-5">
                  {#if checked}
                    <Check class="size-5" />
                  {/if}
                </div>
              {/snippet}
            </Menubar.RadioItem>
          {/each}
        </Menubar.RadioGroup>
      </Menubar.Content>
    </Menubar.Portal>
  </Menubar.Menu>
  <Menubar.Menu>
    <Menubar.Trigger
      class="data-highlighted:bg-muted data-[state=open]:bg-muted inline-flex h-10 cursor-default items-center justify-center rounded-[9px] px-3 text-sm font-medium focus-visible:outline-none"
    >
      Edit
    </Menubar.Trigger>
    <Menubar.Portal>
      <Menubar.Content
        class="focus-override border-muted bg-background shadow-popover focus-visible:outline-hidden z-50 w-full rounded-xl border px-1 py-1.5"
        align="start"
        sideOffset={3}
      >
        <Menubar.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"
        >
          Undo
        </Menubar.Item>
        <Menubar.Item
          class="rounded-button data-highlighted:bg-muted flex h-10 min-w-[130px] select-none items-center py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
        >
          Redo
        </Menubar.Item>
        <Menubar.Separator />
        <Menubar.Sub>
          <Menubar.SubTrigger
            class="rounded-button data-highlighted:bg-muted data-[state=open]:bg-muted flex h-10 select-none items-center gap-3 py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
          >
            Find
            <div class="ml-auto flex items-center">
              <CaretRight class="text-foreground-alt h-4 w-4" />
            </div>
          </Menubar.SubTrigger>
          <Menubar.SubContent
            class="focus-override border-muted bg-background shadow-popover focus-visible:outline-hidden w-full max-w-[209px] rounded-xl border px-1 py-1.5"
          >
            <Menubar.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"
            >
              Search the web
            </Menubar.Item>
            <Menubar.Separator />
            <Menubar.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"
            >
              Find...
            </Menubar.Item>
            <Menubar.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"
            >
              Find Next
            </Menubar.Item>
            <Menubar.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"
            >
              Find Previous
            </Menubar.Item>
          </Menubar.SubContent>
        </Menubar.Sub>
        <Menubar.Separator />
        <Menubar.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"
        >
          Cut
        </Menubar.Item>
        <Menubar.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"
        >
          Copy
        </Menubar.Item>
        <Menubar.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"
        >
          Paste
        </Menubar.Item>
      </Menubar.Content>
    </Menubar.Portal>
  </Menubar.Menu>
  <Menubar.Menu>
    <Menubar.Trigger
      class="rounded-9px data-highlighted:bg-muted data-[state=open]:bg-muted inline-flex h-10 cursor-default items-center justify-center px-3 text-sm font-medium focus-visible:outline-none"
    >
      View
    </Menubar.Trigger>
    <Menubar.Portal>
      <Menubar.Content
        class="focus-override border-muted bg-background shadow-popover focus-visible:outline-hidden z-50 w-full max-w-[220px] rounded-xl border px-1 py-1.5"
        align="start"
        sideOffset={3}
      >
        {#each showConfigs as config, i (config.label + i)}
          <Menubar.CheckboxItem
            class="rounded-button data-highlighted:bg-muted flex h-10 select-none items-center gap-3 py-3 pl-3 pr-1.5 text-sm font-medium focus-visible:outline-none"
            bind:checked={config.checked}
          >
            {#snippet children({ checked })}
              {config.label}
              <div class="ml-auto flex items-center">
                {#if checked}
                  {@render SwitchOn()}
                {:else}
                  {@render SwitchOff()}
                {/if}
              </div>
            {/snippet}
          </Menubar.CheckboxItem>
        {/each}
        <Menubar.Separator />
        <Menubar.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"
        >
          Reload
        </Menubar.Item>
        <Menubar.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"
        >
          Force Reload
        </Menubar.Item>
        <Menubar.Separator />
        <Menubar.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"
        >
          Toggle Fullscreen
        </Menubar.Item>
        <Menubar.Separator />
        <Menubar.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"
        >
          Hide Sidebar
        </Menubar.Item>
      </Menubar.Content>
    </Menubar.Portal>
  </Menubar.Menu>
  <Menubar.Menu>
    <Menubar.Trigger
      class="data-highlighted:bg-muted data-[state=open]:bg-muted mr-[20px] inline-flex h-10 cursor-default items-center justify-center rounded-[9px] px-3 text-sm font-medium focus-visible:outline-none"
    >
      Profiles
    </Menubar.Trigger>
    <Menubar.Portal>
      <Menubar.Content
        class="focus-override border-muted bg-background shadow-popover focus-visible:outline-hidden z-50 w-full max-w-[220px] rounded-xl border px-1 py-1.5"
        align="start"
        sideOffset={3}
      >
        <Menubar.RadioGroup bind:value={selectedProfile}>
          {#each profiles as profile, i (profile.label + i)}
            <Menubar.RadioItem
              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"
              value={profile.value}
            >
              {#snippet children({ checked })}
                {profile.label}
                <div class="ml-auto flex items-center">
                  {#if checked}
                    <Check class="size-5" />
                  {/if}
                </div>
              {/snippet}
            </Menubar.RadioItem>
          {/each}
        </Menubar.RadioGroup>
        <Menubar.Separator />
        <Menubar.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"
          >Edit...</Menubar.Item
        >
        <Menubar.Separator />
        <Menubar.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"
          >Add Profile...</Menubar.Item
        >
      </Menubar.Content>
    </Menubar.Portal>
  </Menubar.Menu>
</Menubar.Root>
{#snippet SwitchOn()}
  <div
    class="bg-dark-10 peer inline-flex h-[15.6px] min-h-[15.6px] w-[26px] shrink-0 items-center rounded-full px-[1.5px]"
  >
    <span
      class="bg-background dark:border-border-input dark:shadow-mini pointer-events-none block size-[13px] shrink-0 translate-x-[10px] rounded-full"
    ></span>
  </div>
{/snippet}
{#snippet SwitchOff()}
  <div
    class="bg-dark-10 shadow-mini-inset peer inline-flex h-[15.6px] w-[26px] shrink-0 items-center rounded-full px-[3px] transition-colors"
  >
    <span
      class="bg-background shadow-mini dark:border-border-input dark:shadow-mini pointer-events-none block size-[13px] shrink-0 translate-x-0 rounded-full transition-transform dark:border"
    ></span>
  </div>
{/snippet}

구조 (Structure)

기본 구조는 Root 안에 여러 Menu를 두고, 각 Menu에 트리거와 콘텐츠를 배치하는 형태예요.

<script lang="ts">
  import { Menubar } from "bits-ui";
</script>
<Menubar.Root>
  <Menubar.Menu>
    <Menubar.Trigger />
    <Menubar.Portal>
      <Menubar.Content>
        <Menubar.Group>
          <Menubar.GroupHeading />
          <Menubar.Item />
        </Menubar.Group>
        <Menubar.Item />
        <Menubar.CheckboxItem>
          {#snippet children({ checked })}
            {checked ? "✅" : ""}
          {/snippet}
        </Menubar.CheckboxItem>
        <Menubar.RadioGroup>
          <Menubar.GroupHeading />
          <Menubar.RadioItem>
            {#snippet children({ checked })}
              {checked ? "✅" : ""}
            {/snippet}
          </Menubar.RadioItem>
        </Menubar.RadioGroup>
        <Menubar.Sub>
          <Menubar.SubTrigger />
          <Menubar.SubContent />
        </Menubar.Sub>
        <Menubar.Separator />
        <Menubar.Arrow />
      </Menubar.Content>
    </Menubar.Portal>
  </Menubar.Menu>
</Menubar.Root>

재사용 컴포넌트 (Reusable Components)

Menubar를 여러 곳에서 쓸 계획이라면, Menubar의 서로 다른 부분을 감싸는 재사용 가능한 컴포넌트를 만들 수 있어요.

아래 예시에서는 메뉴의 트리거, 콘텐츠, 항목을 담고 있는 재사용 MyMenubarMenu 컴포넌트를 만들어요.

<script lang="ts">
  import { Menubar, type WithoutChildrenOrChild } from "bits-ui";
  type Props = WithoutChildrenOrChild<Menubar.MenuProps> & {
    triggerText: string;
    items: { label: string; value: string; onSelect?: () => void }[];
    contentProps?: WithoutChildrenOrChild<Menubar.ContentProps>;
    // other component props if needed
  };
  let { triggerText, items, contentProps, ...restProps }: Props = $props();
</script>
<Menubar.Menu {...restProps}>
  <Menubar.Trigger>
    {triggerText}
  </Menubar.Trigger>
  <Menubar.Content {...contentProps}>
    <Menubar.Group aria-label={triggerText}>
      {#each items as item}
        <Menubar.Item textValue={item.label} onSelect={item.onSelect}>
          {item.label}
        </Menubar.Item>
      {/each}
    </Menubar.Group>
  </Menubar.Content>
</Menubar.Menu>

이제 Menubar.Root 컴포넌트 안에서 MyMenubarMenu 컴포넌트를 사용해 각 메뉴들을 렌더링할 수 있어요.

<script lang="ts">
  import { Menubar } from "bits-ui";
  import MyMenubarMenu from "./MyMenubarMenu.svelte";
  const sales = [
    { label: "Michael Scott", value: "michael" },
    { label: "Dwight Schrute", value: "dwight" },
    { label: "Jim Halpert", value: "jim" },
    { label: "Stanley Hudson", value: "stanley" },
    { label: "Phyllis Vance", value: "phyllis" },
    { label: "Pam Beesly", value: "pam" },
    { label: "Andy Bernard", value: "andy" },
  ];
  const hr = [
    { label: "Toby Flenderson", value: "toby" },
    { label: "Holly Flax", value: "holly" },
    { label: "Jan Levinson", value: "jan" },
  ];
  const accounting = [
    { label: "Angela Martin", value: "angela" },
    { label: "Kevin Malone", value: "kevin" },
    { label: "Oscar Martinez", value: "oscar" },
  ];
  const menubarMenus = [
    { title: "Sales", items: sales },
    { title: "HR", items: hr },
    { title: "Accounting", items: accounting },
  ];
</script>
<Menubar.Root>
  {#each menubarMenus as { title, items }}
    <CustomMenubar triggerText={title} {items} />
  {/each}
</Menubar.Root>

값 상태 관리 (Managing Value State)

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

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

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

<script lang="ts">
  import { Menubar } from "bits-ui";
  let activeValue = $state("");
</script>
<button onclick={() => (activeValue = "menu-1")}>Open Menubar Menu</button>
<Menubar.Root bind:value={activeValue}>
  <Menubar.Menu value="menu-1">
    <!-- ... -->
  </Menubar.Menu>
  <Menubar.Menu value="menu-2">
    <!-- ... -->
  </Menubar.Menu>
</Menubar.Root>

완전 제어 (Fully Controlled)

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

<script lang="ts">
  import { Menubar } from "bits-ui";
  let activeValue = $state("");
  function getValue() {
    return activeValue;
  }
  function setValue(newValue: string) {
    activeValue = newValue;
  }
</script>
<Menubar.Root bind:value={getValue, setValue}>
  <Menubar.Menu value="menu-1">
    <!-- ... -->
  </Menubar.Menu>
  <Menubar.Menu value="menu-2">
    <!-- ... -->
  </Menubar.Menu>
</Menubar.Root>

라디오 그룹 (Radio Groups)

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

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

체크박스 항목 (Checkbox Items)

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

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

체크박스 그룹 (Checkbox Groups)

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

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

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

중첩 메뉴 (Nested Menus)

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

<script lang="ts">
  import { Menubar } from "bits-ui";
</script>
<Menubar.Content>
  <Menubar.Item>Item 1</Menubar.Item>
  <Menubar.Item>Item 2</Menubar.Item>
  <Menubar.Sub>
    <Menubar.SubTrigger>Open Sub Menu</Menubar.SubTrigger>
    <Menubar.SubContent>
      <Menubar.Item>Sub Item 1</Menubar.Item>
      <Menubar.Item>Sub Item 2</Menubar.Item>
    </Menubar.SubContent>
  </Menubar.Sub>
</Menubar.Content>

Svelte Transitions

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

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

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

API Reference

menubar의 상태를 관리하고 범위를 지정하는 루트 menubar 컴포넌트예요.

Property Type Description Details
value $bindable string The value of the currently active menu.Default:  —— undefined
onValueChange function - (value: string) => void A callback function called when the active menu value changes.Default:  —— undefined
dir enum - 'ltr' | 'rtl' The reading direction of the app.Default: 'ltr'
loop boolean Whether or not to loop through the menubar menu triggers when navigating with 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 SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined

menubar 안의 메뉴예요.

Property Type Description Details
value string The value of this menu within the menubar, used to identify it when determining which menu is active.Default:  —— undefined
onOpenChange function - (open: boolean) => void A callback function called when the open state changes.Default:  —— undefined
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-menubar-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-menubar-content '' Present on the content element.
CSS Variable Description Details
--bits-menubar-menu-content-transform-origin The transform origin of the content element.
--bits-menubar-menu-content-available-width The available width of the content element.
--bits-menubar-menu-content-available-height The available height of the content element.
--bits-menubar-menu-anchor-width The width of the anchor element.
--bits-menubar-menu-anchor-height The height of the anchor 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-menubar-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-menubar-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-menubar-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-menubar-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-menubar-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-menubar-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-menubar-arrow '' Present on the arrow element.

메뉴 항목들의 그룹이에요. aria-label을 전달하거나 자식으로 Menubar.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-menubar-group '' Present on the group element.

키보드로 탐색할 때 건너뛰는 그룹 헤딩이에요. 메뉴 항목 그룹에 대한 설명을 제공하며, Menubar.Group이나 Menubar.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-menubar-group-heading '' Present on the group heading element.

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

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-menubar-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-menubar-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-menubar-sub-content '' Present on the submenu content element.

더 알아보기 (Learn more)

Menubar는 Dropdown Menu와 같은 메뉴 프리미티브들을 가로 막대 안에서 함께 쓰는 형태예요. 각 메뉴의 서브메뉴·체크박스·라디오 항목은 Dropdown Menu와 동일한 패턴으로 작동하니, 둘을 함께 보면 메뉴 구조를 자유롭게 설계할 수 있어요.