컨텍스트 메뉴(Context Menu)
마우스 오른쪽 클릭으로 열리는 상황별 옵션과 동작을 표시하는 컴포넌트예요. 특정 요소에 대한 행동(편집, 삭제, 추가 등)을 사용자에게 바로 제공하고 싶을 때 유용해요.
출처: 문서
본문
<script lang="ts">
import { ContextMenu } from "bits-ui";
import CopySimple from "phosphor-svelte/lib/CopySimple";
import MouseSimple from "phosphor-svelte/lib/MouseSimple";
import PencilSimpleLine from "phosphor-svelte/lib/PencilSimpleLine";
import PlusCircle from "phosphor-svelte/lib/PlusCircle";
import Trash from "phosphor-svelte/lib/Trash";
</script>
<ContextMenu.Root>
<ContextMenu.Trigger
class="rounded-card border-border-input text-muted-foreground flex h-[188px] w-[279px] select-none items-center justify-center border-2 border-dashed bg-transparent font-semibold"
>
<div class="flex flex-col items-center justify-center gap-4 text-center">
<MouseSimple class="size-8" />
Right click me
</div>
</ContextMenu.Trigger>
<ContextMenu.Portal>
<ContextMenu.Content
class="border-muted bg-background shadow-popover w-[229px] rounded-xl border px-1 py-1.5 outline-none focus-visible:outline-none"
>
<ContextMenu.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">
<PencilSimpleLine class="text-foreground-alt mr-2 size-5" />
Edit
</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-[13px]"
>
⌘
</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-[11px]"
>
E
</kbd>
</div>
</ContextMenu.Item>
<ContextMenu.Sub>
<ContextMenu.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">
<PlusCircle class="text-foreground-alt mr-2 size-5" />
Add
</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-[13px]"
>
⌘
</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-[11px]"
>
N
</kbd>
</div>
</ContextMenu.SubTrigger>
<ContextMenu.SubContent
class="border-muted bg-background shadow-popover z-100 ring-0! ring-transparent! w-[209px] rounded-xl border px-1 py-1.5"
sideOffset={10}
>
<ContextMenu.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-normal focus-visible:outline-none"
>
Header
</ContextMenu.Item>
<ContextMenu.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-normal focus-visible:outline-none"
>
Paragraph
</ContextMenu.Item>
<ContextMenu.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-normal focus-visible:outline-none"
>
Codeblock
</ContextMenu.Item>
<ContextMenu.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-normal focus-visible:outline-none"
>
List
</ContextMenu.Item>
<ContextMenu.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-normal focus-visible:outline-none"
>
Task
</ContextMenu.Item>
</ContextMenu.SubContent>
</ContextMenu.Sub>
<ContextMenu.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">
<CopySimple class="text-foreground-alt mr-2 size-5" />
Duplicate
</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-[13px]"
>
⌘
</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-[11px]"
>
D
</kbd>
</div>
</ContextMenu.Item>
<ContextMenu.Separator class="bg-muted -mx-1 my-1 block h-px" />
<ContextMenu.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">
<Trash class="text-foreground-alt mr-2 size-5" />
Delete
</div>
</ContextMenu.Item>
</ContextMenu.Content>
</ContextMenu.Portal>
</ContextMenu.Root>
구조(Structure)
<script lang="ts">
import { ContextMenu } from "bits-ui";
</script>
<ContextMenu.Root>
<ContextMenu.Trigger />
<ContextMenu.Portal>
<ContextMenu.Content>
<ContextMenu.Group>
<ContextMenu.GroupHeading />
<ContextMenu.Item />
</ContextMenu.Group>
<ContextMenu.Item />
<ContextMenu.CheckboxItem>
{#snippet children({ checked })}
{checked ? "✅" : ""}
{/snippet}
</ContextMenu.CheckboxItem>
<ContextMenu.RadioGroup>
<ContextMenu.GroupHeading />
<ContextMenu.RadioItem>
{#snippet children({ checked })}
{checked ? "✅" : ""}
{/snippet}
</ContextMenu.RadioItem>
</ContextMenu.RadioGroup>
<ContextMenu.Sub>
<ContextMenu.SubTrigger />
<ContextMenu.SubContent />
</ContextMenu.Sub>
<ContextMenu.Separator />
<ContextMenu.Arrow />
</ContextMenu.Content>
</ContextMenu.Portal>
</ContextMenu.Root>
재사용 컴포넌트(Reusable Components)
컨텍스트 메뉴를 여러 곳에서 쓰려고 한다면, 컨텍스트 메뉴 컴포넌트를 감싸는 재사용 컴포넌트를 만들 수 있어요.
이 예시는 몇 가지 커스텀 prop을 받아 더 유능하게 만든 컨텍스트 메뉴 컴포넌트를 만드는 방법을 보여줘요.
CustomContextMenu.svelte
<script lang="ts">
import type { Snippet } from "svelte";
import { ContextMenu, type WithoutChild } from "bits-ui";
type Props = ContextMenu.Props & {
trigger: Snippet;
items: string[];
contentProps?: WithoutChild<ContextMenu.Content.Props>;
// other component props if needed
};
let {
open = $bindable(false),
children,
trigger,
items,
contentProps,
...restProps
}: Props = $props();
</script>
<ContextMenu.Root bind:open {...restProps}>
<ContextMenu.Trigger>
{@render trigger()}
</ContextMenu.Trigger>
<ContextMenu.Portal>
<ContextMenu.Content {...contentProps}>
<ContextMenu.Group>
<ContextMenu.GroupHeading>Select an Office</ContextMenu.GroupHeading>
{#each items as item}
<ContextMenu.Item textValue={item}>
{item}
</ContextMenu.Item>
{/each}
</ContextMenu.Group>
</ContextMenu.Content>
</ContextMenu.Portal>
</ContextMenu.Root>
그러면 CustomContextMenu 컴포넌트를 이렇게 사용할 수 있어요.
<script lang="ts">
import CustomContextMenu from "./CustomContextMenu.svelte";
</script>
<CustomContextMenu
items={[
"Dunder Mifflin",
"Vance Refrigeration",
"Michael Scott Paper Company",
]}
>
{#snippet triggerArea()}
<div
class="grid size-20 place-items-center rounded-lg border border-dashed p-4"
>
Right-click me
</div>
{/snippet}
</CustomContextMenu>
물론 스니펫을 따로 정의해서 prop으로 전달하는 방식도 가능해요.
<script lang="ts">
import CustomContextMenu from "./CustomContextMenu.svelte";
</script>
{#snippet triggerArea()}
<div
class="grid size-20 place-items-center rounded-lg border border-dashed p-4"
>
Right-click me
</div>
{/snippet}
<CustomContextMenu
items={[
"Dunder Mifflin",
"Vance Refrigeration",
"Michael Scott Paper Company",
]}
{triggerArea}
/>
open 상태 관리하기
이 절에서는 메뉴의 open 상태를 관리하는 방법을 다뤄요.
양방향 바인딩(Two-Way Binding)
bind:open을 사용하면 상태가 자동으로 동기화되어 아주 간단해요.
<script lang="ts">
import { ContextMenu } from "bits-ui";
let isOpen = $state(false);
</script>
<button onclick={() => (isOpen = true)}>Open Context Menu</button>
<ContextMenu.Root bind:open={isOpen}>
<!-- ... -->
</ContextMenu.Root>
완전 제어(Fully Controlled)
함수 바인딩(Function Binding)을 사용하면 상태의 읽기와 쓰기를 완전히 제어할 수 있어요.
<script lang="ts">
import { ContextMenu } from "bits-ui";
let myOpen = $state(false);
function getOpen() {
return myOpen;
}
function setOpen(newOpen: boolean) {
myOpen = newopen;
}
</script>
<ContextMenu.Root bind:open={getOpen, setOpen}>
<!-- ... -->
</ContextMenu.Root>
라디오 그룹(Radio Groups)
ContextMenu.RadioGroup과 ContextMenu.RadioItem 컴포넌트를 결합하면 메뉴 안에 라디오 그룹을 만들 수 있어요.
<script lang="ts">
import { ContextMenu } from "bits-ui";
const values = ["one", "two", "three"];
let value = $state("one");
</script>
<ContextMenu.RadioGroup bind:value>
{#each values as value}
<ContextMenu.RadioItem {value}>
{#snippet children({ checked })}
{#if checked}
✅
{/if}
{value}
{/snippet}
</ContextMenu.RadioItem>
{/each}
</ContextMenu.RadioGroup>
더 자세한 내용은 RadioGroup과 RadioItem API를 참고하세요.
체크박스 항목(Checkbox Items)
ContextMenu.CheckboxItem 컴포넌트를 사용해 menuitemcheckbox 요소를 만들어 메뉴 항목에 체크박스 기능을 추가할 수 있어요.
<script lang="ts">
import { ContextMenu } from "bits-ui";
let notifications = $state(true);
</script>
<ContextMenu.CheckboxItem bind:checked={notifications}>
{#snippet children({ checked, indeterminate })}
{#if indeterminate}
-
{:else if checked}
✅
{/if}
Notifications
{/snippet}
</ContextMenu.CheckboxItem>
더 자세한 내용은 CheckboxItem API를 참고하세요.
체크박스 그룹(Checkbox Groups)
ContextMenu.CheckboxItem 컴포넌트 집합 주위에 ContextMenu.CheckboxGroup 컴포넌트를 사용하면 메뉴 안에 체크박스 그룹을 만들 수 있어요. 이때 value prop은 선택된 값들의 배열이에요.
<script lang="ts">
import { ContextMenu } from "bits-ui";
let colors = $state<string[]>([]);
</script>
<ContextMenu.CheckboxGroup bind:value={colors}>
<ContextMenu.GroupHeading>Favorite color</ContextMenu.GroupHeading>
<ContextMenu.CheckboxItem value="red">
{#snippet children({ checked })}
{#if checked}
✅
{/if}
Red
{/snippet}
</ContextMenu.CheckboxItem>
<ContextMenu.CheckboxItem value="blue">
{#snippet children({ checked })}
{#if checked}
✅
{/if}
Blue
{/snippet}
</ContextMenu.CheckboxItem>
<ContextMenu.CheckboxItem value="green">
{#snippet children({ checked })}
{#if checked}
✅
{/if}
Green
{/snippet}
</ContextMenu.CheckboxItem>
</ContextMenu.CheckboxGroup>
value 상태는 메뉴가 열렸다 닫히는 사이클 사이에 유지되지 않아요. 상태를 유지하려면 $state 변수에 저장해서 value prop으로 전달해야 해요.
중첩 메뉴(Nested Menus)
ContextMenu.Sub 컴포넌트를 사용하면 복잡한 메뉴 구조를 만들 수 있는 중첩 메뉴를 만들 수 있어요.
아래 예시는 라디오 그룹, 체크박스 그룹, 여러 개의 중첩 서브메뉴가 있는 더 깊은 계층 구조를 보여줘요(프로젝트 트래커에서 이슈를 필터링하는 것과 비슷해요).
코드 펼치기(Expand Code)
<script lang="ts">
import { ContextMenu } from "bits-ui";
import CaretRight from "phosphor-svelte/lib/CaretRight";
import Check from "phosphor-svelte/lib/Check";
import MouseSimple from "phosphor-svelte/lib/MouseSimple";
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}
<ContextMenu.Root>
<ContextMenu.Trigger
class="rounded-card border-border-input text-muted-foreground flex h-[220px] w-full max-w-[320px] select-none items-center justify-center border-2 border-dashed bg-transparent text-sm font-semibold"
>
<div class="flex flex-col items-center justify-center gap-3 text-center">
<MouseSimple class="size-8" />
<span>Right-click this issue card</span>
</div>
</ContextMenu.Trigger>
<ContextMenu.Portal>
<ContextMenu.Content class={contentClass} sideOffset={8}>
<ContextMenu.Item class={itemClass} disabled
>Search issues…</ContextMenu.Item
>
<ContextMenu.Sub>
<ContextMenu.SubTrigger class={subTriggerClass}>
Status
<CaretRight class="text-foreground-alt ml-auto size-4" />
</ContextMenu.SubTrigger>
<ContextMenu.Portal>
<ContextMenu.SubContent class={subContentClass} sideOffset={10}>
<ContextMenu.RadioGroup bind:value={selectedStatus}>
{#each statusItems as item (item.value)}
<ContextMenu.RadioItem value={item.value} class={itemClass}>
{#snippet children({ checked })}
{item.label}
{@render radioCheckedIndicator(checked)}
{/snippet}
</ContextMenu.RadioItem>
{/each}
</ContextMenu.RadioGroup>
</ContextMenu.SubContent>
</ContextMenu.Portal>
</ContextMenu.Sub>
<ContextMenu.Sub>
<ContextMenu.SubTrigger class={subTriggerClass}>
Issue properties
<CaretRight class="text-foreground-alt ml-auto size-4" />
</ContextMenu.SubTrigger>
<ContextMenu.Portal>
<ContextMenu.SubContent class={subContentClass} sideOffset={10}>
<ContextMenu.Sub>
<ContextMenu.SubTrigger class={subTriggerClass}>
Priority
<CaretRight class="text-foreground-alt ml-auto size-4" />
</ContextMenu.SubTrigger>
<ContextMenu.Portal>
<ContextMenu.SubContent class={subContentClass} sideOffset={10}>
<ContextMenu.RadioGroup bind:value={selectedPriority}>
{#each priorityItems as item (item.value)}
<ContextMenu.RadioItem
value={item.value}
class={itemClass}
>
{#snippet children({ checked })}
{item.label}
{@render radioCheckedIndicator(checked)}
{/snippet}
</ContextMenu.RadioItem>
{/each}
</ContextMenu.RadioGroup>
</ContextMenu.SubContent>
</ContextMenu.Portal>
</ContextMenu.Sub>
<ContextMenu.Sub>
<ContextMenu.SubTrigger class={subTriggerClass}>
Type
<CaretRight class="text-foreground-alt ml-auto size-4" />
</ContextMenu.SubTrigger>
<ContextMenu.Portal>
<ContextMenu.SubContent class={subContentClass} sideOffset={10}>
<ContextMenu.RadioGroup bind:value={selectedType}>
{#each typeItems as item (item.value)}
<ContextMenu.RadioItem
value={item.value}
class={itemClass}
>
{#snippet children({ checked })}
{item.label}
{@render radioCheckedIndicator(checked)}
{/snippet}
</ContextMenu.RadioItem>
{/each}
</ContextMenu.RadioGroup>
</ContextMenu.SubContent>
</ContextMenu.Portal>
</ContextMenu.Sub>
<ContextMenu.Separator class="bg-muted -mx-1 my-1 block h-px" />
<ContextMenu.CheckboxGroup bind:value={digestPrefs}>
<ContextMenu.GroupHeading
class="text-muted-foreground px-3 pb-2 pt-3 text-xs font-medium"
>
Email digest
</ContextMenu.GroupHeading>
{#each digestItems as item (item.value)}
<ContextMenu.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}
</ContextMenu.CheckboxItem>
{/each}
</ContextMenu.CheckboxGroup>
<ContextMenu.Sub>
<ContextMenu.SubTrigger class={subTriggerClass}>
Labels
<CaretRight class="text-foreground-alt ml-auto size-4" />
</ContextMenu.SubTrigger>
<ContextMenu.Portal>
<ContextMenu.SubContent class={subContentClass} sideOffset={10}>
<ContextMenu.RadioGroup bind:value={selectedLabel}>
{#each labelItems as item (item.value)}
<ContextMenu.RadioItem
value={item.value}
class={itemClass}
>
{#snippet children({ checked })}
{item.label}
{@render radioCheckedIndicator(checked)}
{/snippet}
</ContextMenu.RadioItem>
{/each}
</ContextMenu.RadioGroup>
<ContextMenu.Sub>
<ContextMenu.SubTrigger class={subTriggerClass}>
Product area
<CaretRight class="text-foreground-alt ml-auto size-4" />
</ContextMenu.SubTrigger>
<ContextMenu.Portal>
<ContextMenu.SubContent
class={subContentClass}
sideOffset={10}
>
<ContextMenu.Item class={itemClass}
>Web app</ContextMenu.Item
>
<ContextMenu.Item class={itemClass}
>Mobile</ContextMenu.Item
>
<ContextMenu.Item class={itemClass}
>CLI</ContextMenu.Item
>
<ContextMenu.Item class={itemClass}
>Marketing site</ContextMenu.Item
>
</ContextMenu.SubContent>
</ContextMenu.Portal>
</ContextMenu.Sub>
</ContextMenu.SubContent>
</ContextMenu.Portal>
</ContextMenu.Sub>
</ContextMenu.SubContent>
</ContextMenu.Portal>
</ContextMenu.Sub>
</ContextMenu.Content>
</ContextMenu.Portal>
</ContextMenu.Root>
<script lang="ts">
import { ContextMenu } from "bits-ui";
</script>
<ContextMenu.Content>
<ContextMenu.Item>Item 1</ContextMenu.Item>
<ContextMenu.Item>Item 2</ContextMenu.Item>
<ContextMenu.Sub>
<ContextMenu.SubTrigger>Open Sub Menu</ContextMenu.SubTrigger>
<ContextMenu.SubContent>
<ContextMenu.Item>Sub Item 1</ContextMenu.Item>
<ContextMenu.Item>Sub Item 2</ContextMenu.Item>
</ContextMenu.SubContent>
</ContextMenu.Sub>
</ContextMenu.Content>
Svelte 트랜지션(Svelte Transitions)
forceMount prop과 child 스니펫을 함께 사용하면 ContextMenu.Content 컴포넌트를 강제로 마운트해서 Svelte 트랜지션 또는 더 많은 제어가 필요한 다른 애니메이션 라이브러리를 쓸 수 있어요.
<script lang="ts">
import { ContextMenu } from "bits-ui";
import { fly } from "svelte/transition";
</script>
<ContextMenu.Content forceMount>
{#snippet child({ wrapperProps, props, open })}
{#if open}
<div {...wrapperProps}>
<div {...props} transition:fly>
<ContextMenu.Item>Item 1</ContextMenu.Item>
<ContextMenu.Item>Item 2</ContextMenu.Item>
</div>
</div>
{/if}
{/snippet}
</ContextMenu.Content>
물론 이건 가장 예쁜 문법은 아니에요. 이 방식을 쓸 거라면 이 로직을 처리하는 재사용 콘텐츠 컴포넌트를 직접 만드는 걸 권장해요. Bits UI 컴포넌트에서 트랜지션을 사용하는 방법에 대한 자세한 내용은 Transitions 문서를 참고하세요.
코드 펼치기(Expand Code)
<script lang="ts">
import { ContextMenu } from "bits-ui";
import CopySimple from "phosphor-svelte/lib/CopySimple";
import MouseSimple from "phosphor-svelte/lib/MouseSimple";
import PencilSimpleLine from "phosphor-svelte/lib/PencilSimpleLine";
import PlusCircle from "phosphor-svelte/lib/PlusCircle";
import Trash from "phosphor-svelte/lib/Trash";
import { fly } from "svelte/transition";
</script>
<ContextMenu.Root>
<ContextMenu.Trigger
class="rounded-card border-input text-muted-foreground flex h-[188px] w-[279px] select-none items-center justify-center border-2 border-dashed bg-transparent font-semibold"
>
<div class="flex flex-col items-center justify-center gap-4 text-center">
<MouseSimple class="size-8" />
Right click me
</div>
</ContextMenu.Trigger>
<ContextMenu.Portal>
<ContextMenu.Content
class="focus-override border-muted bg-background shadow-popover w-[229px] rounded-xl border px-1 py-1.5 focus-visible:outline-none"
forceMount
>
{#snippet child({ wrapperProps, props, open })}
{#if open}
<div {...wrapperProps}>
<div {...props} transition:fly={{ duration: 300 }}>
<ContextMenu.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">
<PencilSimpleLine class="text-foreground-alt mr-2 size-5" />
Edit
</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-[13px]"
>
⌘
</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-[11px]"
>
E
</kbd>
</div>
</ContextMenu.Item>
<ContextMenu.Sub>
<ContextMenu.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">
<PlusCircle class="text-foreground-alt mr-2 size-5" />
Add
</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-[13px]"
>
⌘
</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-[11px]"
>
N
</kbd>
</div>
</ContextMenu.SubTrigger>
<ContextMenu.SubContent
class="border-muted bg-background shadow-popover z-100 ring-0! ring-transparent! w-[209px] rounded-xl border px-1 py-1.5"
sideOffset={10}
>
<ContextMenu.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-normal focus-visible:outline-none"
>
Header
</ContextMenu.Item>
<ContextMenu.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-normal focus-visible:outline-none"
>
Paragraph
</ContextMenu.Item>
<ContextMenu.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-normal focus-visible:outline-none"
>
Codeblock
</ContextMenu.Item>
<ContextMenu.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-normal focus-visible:outline-none"
>
List
</ContextMenu.Item>
<ContextMenu.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-normal focus-visible:outline-none"
>
Task
</ContextMenu.Item>
</ContextMenu.SubContent>
</ContextMenu.Sub>
<ContextMenu.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">
<CopySimple class="text-foreground-alt mr-2 size-5" />
Duplicate
</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-[13px]"
>
⌘
</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-[11px]"
>
D
</kbd>
</div>
</ContextMenu.Item>
<ContextMenu.Separator class="bg-muted -mx-1 my-1 block h-px" />
<ContextMenu.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">
<Trash class="text-foreground-alt mr-2 size-5" />
Delete
</div>
</ContextMenu.Item>
</div>
</div>
{/if}
{/snippet}
</ContextMenu.Content>
</ContextMenu.Portal>
</ContextMenu.Root>
API 참조(API Reference)
ContextMenu.Root
컨텍스트 메뉴의 상태를 관리하고 범위를 지정하는 루트 컴포넌트예요.
| 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 |
ContextMenu.Trigger
오른쪽 클릭하면 컨텍스트 메뉴를 여는 요소예요.
| Property | Type | Description | Details |
|---|---|---|---|
disabled |
boolean |
Whether or not the menu trigger is disabled.Default: false |
|
ref $bindable |
HTMLDivElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { 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-context-menu-trigger |
'' |
Present on the trigger element. |
ContextMenu.Portal
드롭다운 메뉴의 콘텐츠를 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 |
ContextMenu.Content
컨텍스트 메뉴가 열려 있을 때 표시되는 콘텐츠예요.
| 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 |
|
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' |
|
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 |
|
loop |
boolean |
Whether or not the context menu should loop through items when reaching the end.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-context-menu-content |
'' |
Present on the content element. |
| CSS Variable | Description | Details |
|---|---|---|
--bits-context-menu-content-transform-origin |
The transform origin of the content element. | |
--bits-context-menu-content-available-width |
The available width of the content element. | |
--bits-context-menu-content-available-height |
The available height of the content element. | |
--bits-context-menu-anchor-width |
The width of the anchor element. | |
--bits-context-menu-anchor-height |
The height of the anchor element. |
ContextMenu.ContentStatic
컨텍스트 메뉴가 열려 있을 때 표시되는 콘텐츠예요. (정적/Floting 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 |
|
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' |
|
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 |
|
loop |
boolean |
Whether or not the context menu should loop through items when reaching the end.Default: false |
|
ref $bindable |
HTMLDivElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { 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-context-menu-content |
'' |
Present on the content element. |
ContextMenu.Item
컨텍스트 메뉴 안의 메뉴 항목이에요.
| 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-context-menu-item |
'' |
Present on the item element. |
ContextMenu.CheckboxGroup
한 번에 여러 개를 체크할 수 있는 체크박스 메뉴 항목들의 그룹이에요.
| 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-context-menu-checkbox-group |
'' |
Present on the checkbox group element. |
ContextMenu.CheckboxItem
체크박스처럼 제어하고 토글할 수 있는 메뉴 항목이에요.
| 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-context-menu-checkbox-item |
'' |
Present on the checkbox item element. |
ContextMenu.RadioGroup
한 번에 하나만 체크할 수 있는 라디오 메뉴 항목들의 그룹이에요.
| 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-context-menu-radio-group |
'' |
Present on the radio group element. |
ContextMenu.RadioItem
라디오 버튼처럼 제어하고 토글할 수 있는 메뉴 항목이에요. 반드시 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-context-menu-radio-item |
'' |
Present on the radio item element. |
ContextMenu.Separator
메뉴 항목을 시각적으로 구분하는 가로선이에요.
| 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-context-menu-separator |
'' |
Present on the separator element. |
ContextMenu.Arrow
컨텍스트 메뉴의 앵커/트리거 지점을 가리키는 선택적 화살표예요.
| 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-context-menu-arrow |
'' |
Present on the arrow element. |
ContextMenu.Group
메뉴 항목들의 그룹이에요. aria-label을 전달하거나 자식으로 ContextMenu.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-context-menu-group |
'' |
Present on the group element. |
ContextMenu.GroupHeading
키보드로 탐색할 때 건너뛰는 그룹의 제목이에요. 메뉴 항목 그룹에 시각적 라벨을 제공하는 데 쓰이며, 반드시 ContextMenu.Group 또는 ContextMenu.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-menu-group-heading |
'' |
Present on the group heading element. |
ContextMenu.Sub
부모 컨텍스트 메뉴에 속한 서브메뉴예요. 서브메뉴의 상태를 관리하는 역할을 해요.
| 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 |
ContextMenu.SubTrigger
누르거나 호버하면 자신이 속한 서브메뉴를 여는 메뉴 항목이에요.
| 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-context-menu-sub-trigger |
'' |
Present on the submenu trigger element. |
ContextMenu.SubContent
부모 서브메뉴가 열려 있을 때 표시되는 서브메뉴 콘텐츠예요.
| 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-context-menu-sub-content |
'' |
Present on the submenu content element. |
ContextMenu.SubContentStatic
부모 서브메뉴가 열려 있을 때 표시되는 서브메뉴 콘텐츠예요. (정적/Floting 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-context-menu-sub-content |
'' |
Present on the submenu content element. |
더 알아보기 (Learn more)
오른쪽 클릭이 아닌 클릭으로 여는 일반 드롭다운 메뉴가 필요하다면 드롭다운 메뉴(Dropdown Menu) 컴포넌트를 살펴보세요. 메뉴 안에서 선택·그룹화를 다루는 개념은 라디오 그룹(Radio Group) 문서에서도 이어집니다.