경고 다이얼로그(Alert Dialog)
사용자에게 중요한 결정을 확인받거나 입력을 요구할 때, 현재 화면을 떠나지 않으면서 집중을 유도하는 모달 창이 필요하죠. Alert Dialog 컴포넌트가 바로 그런 상황을 깔끔하게 처리해 줘요.
출처: 문서
본문
<script lang="ts">
import { AlertDialog } from "bits-ui";
</script>
<AlertDialog.Root>
<AlertDialog.Trigger
class="rounded-input bg-dark text-background
shadow-mini hover:bg-dark/95 inline-flex h-12 select-none
items-center justify-center whitespace-nowrap px-[21px] text-[15px] font-semibold transition-all active:scale-[0.98]"
>
Subscribe
</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay
class="data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80"
/>
<AlertDialog.Content
class="rounded-card-lg bg-background shadow-popover data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 outline-hidden fixed left-[50%] top-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 border p-7 sm:max-w-lg md:w-full "
>
<div class="flex flex-col gap-4 pb-6">
<AlertDialog.Title class="text-lg font-semibold tracking-tight">
Confirm your transaction
</AlertDialog.Title>
<AlertDialog.Description class="text-foreground-alt text-sm">
This action cannot be undone. This will initiate a monthly wire in the
amount of $10,000 to Huntabyte. Do you wish to continue?
</AlertDialog.Description>
</div>
<div class="flex w-full items-center justify-center gap-2">
<AlertDialog.Cancel
class="h-input rounded-input bg-muted shadow-mini hover:bg-dark-10 focus-visible:ring-foreground focus-visible:ring-offset-background focus-visible:outline-hidden inline-flex w-full items-center justify-center text-[15px] font-medium transition-all focus-visible:ring-2 focus-visible:ring-offset-2 active:scale-[0.98]"
>
Cancel
</AlertDialog.Cancel>
<AlertDialog.Action
class="h-input rounded-input bg-dark text-background shadow-mini hover:bg-dark/95 focus-visible:ring-dark focus-visible:ring-offset-background focus-visible:outline-hidden inline-flex w-full items-center justify-center text-[15px] font-semibold transition-all focus-visible:ring-2 focus-visible:ring-offset-2 active:scale-[0.98]"
>
Continue
</AlertDialog.Action>
</div>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
주요 기능(Key Features)
- 복합 컴포넌트 구조(Compound Component Structure): 서브 컴포넌트들을 조합해 유연하고 커스터마이징 가능한 경고 다이얼로그를 만들 수 있어요.
- 접근성(Accessibility): ARIA를 준수하고 완전한 키보드 내비게이션을 지원해요.
- 포털 지원(Portal Support): 콘텐츠를 일반 DOM 계층 밖에 렌더링해서 쌓임(stacking) 문제를 피해요.
- 포커스 관리(Managed Focus): 포커스를 자동으로 트랩하며 커스터마이징 옵션도 제공해요.
- 유연한 상태(Flexible State): 제어(controlled)와 비제어(uncontrolled) 열림 상태를 모두 지원해요.
구조(Structure)
Alert Dialog는 각각의 목적이 뚜렷한 서브 컴포넌트들로 구성돼요.
- Root: 상태를 관리하고 자식 컴포넌트에 컨텍스트를 제공해요.
- Trigger: 다이얼로그의 열림/닫힘 상태를 토글해요.
- Portal: 자식들을 일반 DOM 계층 밖의 포털에 렌더링해요.
- Overlay: 다이얼로그 뒤에 배경(backdrop)을 표시해요.
- Content: 다이얼로그의 본문 콘텐츠를 담아요.
- Title: 다이얼로그의 제목을 표시해요.
- Description: 다이얼로그에 대한 설명이나 추가 맥락을 표시해요.
- Cancel: 동작 없이 다이얼로그를 닫아요.
- Action: 다이얼로그의 동작을 확인해요.
다음은 Alert Dialog의 간단한 예시예요.
<script lang="ts">
import { AlertDialog } from "bits-ui";
</script>
<AlertDialog.Root>
<AlertDialog.Trigger>Open Dialog</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay />
<AlertDialog.Content>
<AlertDialog.Title>Confirm Action</AlertDialog.Title>
<AlertDialog.Description>Are you sure?</AlertDialog.Description>
<AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
<AlertDialog.Action>Confirm</AlertDialog.Action>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
재사용 컴포넌트(Reusable Components)
앱 전반에 걸쳐 일관성을 유지하려면 재사용 가능한 Alert Dialog 컴포넌트를 만들어 두는 게 좋아요. 다음은 그 예시예요.
MyAlertDialog.svelte
<script lang="ts">
import type { Snippet } from "svelte";
import { AlertDialog, type WithoutChild } from "bits-ui";
type Props = AlertDialog.RootProps & {
buttonText: string;
title: Snippet;
description: Snippet;
contentProps?: WithoutChild<AlertDialog.ContentProps>;
// ...other component props if you wish to pass them
};
let {
open = $bindable(false),
children,
buttonText,
contentProps,
title,
description,
...restProps
}: Props = $props();
</script>
<AlertDialog.Root bind:open {...restProps}>
<AlertDialog.Trigger>
{buttonText}
</AlertDialog.Trigger>
<AlertDialog.Portal>
<AlertDialog.Overlay />
<AlertDialog.Content {...contentProps}>
<AlertDialog.Title>
{@render title()}
</AlertDialog.Title>
<AlertDialog.Description>
{@render description()}
</AlertDialog.Description>
{@render children?.()}
<AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
<AlertDialog.Action>Confirm</AlertDialog.Action>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
그러면 앱에서는 MyAlertDialog 컴포넌트를 이렇게 사용할 수 있어요.
+page.svelte
<script lang="ts">
import MyAlertDialog from "$lib/components/MyAlertDialog.svelte";
</script>
<MyAlertDialog buttonText="Open Dialog">
{#snippet title()}
Delete your account
{/snippet}
{#snippet description()}
This action cannot be undone.
{/snippet}
</MyAlertDialog>
물론 스니펫을 따로 정의해서 prop으로 전달하는 방식도 가능해요.
+page.svelte
<script lang="ts">
import MyAlertDialog from "$lib/components/MyAlertDialog.svelte";
</script>
{#snippet title()}
Delete your account
{/snippet}
{#snippet description()}
This action cannot be undone.
{/snippet}
<MyAlertDialog buttonText="Open Dialog" {title} {description}>
<!-- ... additional content here -->
</MyAlertDialog>
팁(Tip)
단순함을 원하면 문자열 prop을, 동적인 콘텐츠가 필요하면 스니펫을 사용하세요.
open 상태 관리하기
이 절에서는 Alert Dialog의 open 상태를 관리하는 방법을 다뤄요.
양방향 바인딩(Two-Way Binding)
bind:open을 사용하면 상태가 자동으로 동기화되어 아주 간단해요.
<script lang="ts">
import { AlertDialog } from "bits-ui";
let isOpen = $state(false);
</script>
<button onclick={() => (isOpen = true)}>Open Dialog</button>
<AlertDialog.Root bind:open={isOpen}>
<!-- ... -->
</AlertDialog.Root>
완전 제어(Fully Controlled)
함수 바인딩(Function Binding)을 사용하면 상태를 완전히 제어할 수 있어요.
<script lang="ts">
import { AlertDialog } from "bits-ui";
let myOpen = $state(false);
function getOpen() {
return myOpen;
}
function setOpen(newOpen: boolean) {
myOpen = newOpen;
}
</script>
<AlertDialog.Root bind:open={getOpen, setOpen}>
<!-- ... -->
</AlertDialog.Root>
상태 관리에 대해 더 자세히 알고 싶다면 State Management 문서를 참고하세요.
포커스 관리(Focus Management)
포커스 트랩(Focus Trap)
기본적으로 다이얼로그 안에 포커스가 가둬져요. 해제하려면 이렇게 해요.
<AlertDialog.Content trapFocus={false}>
<!-- ... -->
</AlertDialog.Content>
경고(Warning)
포커스 트랩을 끄면 접근성이 떨어질 수 있어요. 신중하게 사용하세요.
열릴 때 포커스(Open Focus)
기본적으로 다이얼로그가 열리면 AlertDialog.Content에 포커스가 이동해요. 화면 낭독기가 콘텐츠를 제대로 읽기 위해 필요한 동작이고, 키보드로 이동하는 사용자가 다이얼로그 안에서 상호작용할 지점에 닿도록 보장하기도 해요.
이 동작은 AlertDialog.Content 컴포넌트의 onOpenAutoFocus prop으로 바꿀 수 있어요. 이 prop을 사용해 다이얼로그 안의 어떤 것에는 반드시 포커스를 주는 걸 강력히 권장해요.
먼저 onOpenAutoFocus 콜백에 전달된 이벤트를 취소해 기본적으로 첫 포커스 가능한 요소로 가는 동작을 막은 뒤, 원하는 요소에 포커스를 주면 돼요.
<script lang="ts">
import { AlertDialog } from "bits-ui";
let nameInput = $state<HTMLInputElement>();
</script>
<AlertDialog.Root>
<AlertDialog.Trigger>Open AlertDialog</AlertDialog.Trigger>
<AlertDialog.Content
onOpenAutoFocus={(e) => {
e.preventDefault();
nameInput?.focus();
}}
>
<input type="text" bind:this={nameInput} />
</AlertDialog.Content>
</AlertDialog.Root>
닫힐 때 포커스(Close Focus)
기본적으로 다이얼로그가 닫히면 트리거 요소에 포커스가 이동해요. AlertDialog.Content 컴포넌트의 onCloseAutoFocus prop으로 이 동작을 바꿀 수 있어요.
onCloseAutoFocus 콜백에 전달된 이벤트를 취소해 트리거로 가는 기본 동작을 막고, 원하는 요소에 포커스를 주면 돼요.
<script lang="ts">
import { AlertDialog } from "bits-ui";
let nameInput = $state<HTMLInputElement>();
</script>
<input type="text" bind:this={nameInput} />
<AlertDialog.Root>
<AlertDialog.Trigger>Open AlertDialog</AlertDialog.Trigger>
<AlertDialog.Content
onCloseAutoFocus={(e) => {
e.preventDefault();
nameInput?.focus();
}}
>
<!-- ... -->
</AlertDialog.Content>
</AlertDialog.Root>
고급 동작(Advanced Behaviors)
Alert Dialog는 동작을 커스터마이징하고 사용자 경험을 개선할 수 있는 몇 가지 고급 기능을 제공해요. 이 절에서는 스크롤 잠금, Escape 키 처리, 다이얼로그 바깥 상호작용을 다뤄요.
스크롤 잠금(Scroll Lock)
기본적으로 Alert Dialog가 열리면 body 스크롤이 비활성화돼요. 이렇게 하면 다이얼로그 콘텐츠에 사용자의 주의를 집중시키는, 네이티브에 가까운 경험을 제공해요.
스크롤 동작 커스터마이징
다이얼로그가 열려 있을 때 body 스크롤을 허용하려면 AlertDialog.Content의 preventScroll prop을 사용해요.
<AlertDialog.Content preventScroll={false}>
<!-- ... -->
</AlertDialog.Content>
참고(Note)
body 스크롤을 허용하면 사용자의 포커스와 접근성에 영향을 줄 수 있어요. 현명하게 판단해서 쓰세요.
Escape 키 처리
기본적으로 Escape 키를 누르면 열려 있는 Alert Dialog가 닫혀요. Bits UI는 이 동작을 커스터마이징하는 두 가지 방법을 제공해요.
방법 1: escapeKeydownBehavior
escapeKeydownBehavior prop은 Escape 키가 눌렸을 때 컴포넌트가 취할 동작을 커스터마이징할 수 있게 해줘요. 다음 값 중 하나를 받아요.
'close'(기본값): Alert Dialog를 즉시 닫아요.'ignore': Alert Dialog가 닫히지 않도록 막아요.'defer-otherwise-close': 상위 Bits UI 컴포넌트가 이 prop도 구현했다면 닫힘 결정을 그 컴포넌트에 위임해요. 그렇지 않으면 Alert Dialog가 즉시 닫혀요.'defer-otherwise-ignore': 상위 Bits UI 컴포넌트가 이 prop도 구현했다면 닫힘 결정을 그 컴포넌트에 위임해요. 그렇지 않으면 Alert Dialog가 키 입력을 무시하고 닫히지 않아요.
Escape 키를 눌러도 항상 닫히지 않게 하려면 Dialog.Content의 escapeKeydownBehavior prop을 'ignore'로 설정하면 돼요.
<AlertDialog.Content escapeKeydownBehavior="ignore">
<!-- ... -->
</AlertDialog.Content>
방법 2: onEscapeKeydown
더 세밀한 제어가 필요하다면 onEscapeKeydown prop으로 기본 동작을 재정의할 수 있어요.
<AlertDialog.Content
onEscapeKeydown={(e) => {
e.preventDefault();
// do something else instead
}}
>
<!-- ... -->
</AlertDialog.Content>
이 방법으로 Escape 키가 눌렸을 때 커스텀 로직을 구현할 수 있어요.
바깥 상호작용(Interaction Outside)
기본적으로 Alert Dialog 콘텐츠 영역 바깥과 상호작용해도 다이얼로그는 닫히지 않아요. Bits UI는 이 동작을 바꾸는 두 가지 방법을 제공해요.
방법 1: interactOutsideBehavior
interactOutsideBehavior prop은 콘텐츠 바깥에서 상호작용(터치, 마우스, 포인터 이벤트)이 발생했을 때 컴포넌트가 취할 동작을 커스터마이징할 수 있게 해줘요. 다음 값 중 하나를 받아요.
'ignore'(기본값): Alert Dialog가 닫히지 않도록 막아요.'close': Alert Dialog를 즉시 닫아요.'defer-otherwise-close': 상위 Bits UI 컴포넌트가 이 prop도 구현했다면 닫힘 결정을 그 컴포넌트에 위임해요. 그렇지 않으면 Alert Dialog가 즉시 닫혀요.'defer-otherwise-ignore': 상위 Bits UI 컴포넌트가 이 prop도 구현했다면 닫힘 결정을 그 컴포넌트에 위임해요. 그렇지 않으면 Alert Dialog가 이벤트를 무시하고 닫히지 않아요.
콘텐츠 바깥에서 상호작용할 때 Alert Dialog가 닫히게 하려면 AlertDialog.Content의 interactOutsideBehavior prop을 'close'로 설정하면 돼요.
<AlertDialog.Content interactOutsideBehavior="ignore">
<!-- ... -->
</AlertDialog.Content>
방법 2: onInteractOutside
바깥 상호작용을 커스텀하게 처리하려면 onInteractOutside prop으로 기본 동작을 재정의할 수 있어요.
<AlertDialog.Content
onInteractOutside={(e) => {
e.preventDefault();
// do something else instead
}}
>
<!-- ... -->
</AlertDialog.Content>
이 방법으로 사용자들이 Alert Dialog 콘텐츠 바깥과 상호작용할 때 특정 동작을 구현할 수 있어요.
모범 사례(Best Practices)
- 스크롤 잠금: 스크롤 잠금을 해제하기 전에 자신의 사용 사례를 신중히 고려하세요. 스크롤 가능한 콘텐츠가 있는 다이얼로그나 특정 UX 요구에는 필요할 수 있어요.
- Escape 키: 기본 escape 키 동작을 덮어쓰는 건 신중하게 해야 해요. 사용자들은 보통 escape 키로 모달이 닫히길 기대하기 때문이에요.
- 바깥 상호작용: 바깥 상호작용을 무시하면 중요한 다이얼로그나 여러 단계로 진행되는 프로세스에 유용할 수 있지만, 사용자를 의도치 않게 가둬버리지 않도록 주의해야 해요.
- 접근성: 어떤 커스터마이징을 하든 다이얼로그의 접근성을 유지하거나 향상시키도록 항상 확인하세요.
- 사용자 기대: 일반적인 UX 패턴과 커스텀 동작의 균형을 맞춰 사용자들이 혼란스러워하지 않게 하세요.
이 고급 기능들을 잘 활용하면 사용성과 접근성 기준을 지키면서도 매우 커스터마이즈된 다이얼로그 경험을 만들 수 있어요.
중첩 다이얼로그(Nested Dialogs)
Alert Dialog는 서로(또는 일반 Dialog와) 중첩시켜 더 복잡한 레이아웃을 만들 수 있어요. 중첩 다이얼로그 추적과 스타일링 기능도 동일하게 제공돼요.
중첩 Alert Dialog 스타일링
Alert Dialog는 일반 Dialog와 동일한 데이터 속성과 CSS 변수를 통해 중첩을 추적할 수 있게 해줘요.
데이터 속성(Data Attributes):
data-nested-open: 중첩 다이얼로그가 열려 있을 때AlertDialog.Content와AlertDialog.Overlay에 표시돼요.data-nested: 다이얼로그가 중첩 다이얼로그일 때AlertDialog.Content와AlertDialog.Overlay에 표시돼요. 중첩 다이얼로그의 오버레이가 부모와 겹치지 않도록 숨기는 데 유용해요.
CSS 변수(CSS Variables):
--bits-dialog-depth: 중첩 깊이(0은 루트, 1은 첫 번째 중첩 등)예요.--bits-dialog-nested-count: 현재 열려 있는 중첩 다이얼로그의 개수예요(반응형으로 갱신돼요).
<AlertDialog.Content
style="transform: scale(calc(1 - var(--dialog-nested-count) * 0.05));"
>
<!-- Alert dialog content -->
</AlertDialog.Content>
Svelte 트랜지션(Svelte Transitions)
다이얼로그 컴포넌트에서의 Svelte 트랜지션에 대해 더 자세히 알고 싶다면 Dialog 컴포넌트 문서를 참고하세요.
폼 다루기(Working with Forms)
폼 제출(Form Submission)
AlertDialog 컴포넌트를 사용할 때 Action 버튼을 클릭하면 폼을 제출하거나 비동기 작업을 수행하고 싶은 경우가 많아요.
이런 경우 비동기 작업이 끝날 때까지 기다린 뒤 프로그래밍 방식으로 다이얼로그를 닫으면 됩니다.
<script lang="ts">
import { AlertDialog } from "bits-ui";
function wait(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
let open = $state(false);
</script>
<AlertDialog.Root bind:open>
<AlertDialog.Portal>
<AlertDialog.Overlay />
<AlertDialog.Content>
<AlertDialog.Title>Confirm your action</AlertDialog.Title>
<AlertDialog.Description
>Are you sure you want to do this?</AlertDialog.Description
>
<form
method="POST"
action="?/someAction"
onsubmit={() => {
wait(1000).then(() => (open = false));
}}
>
<AlertDialog.Cancel type="button"
>No, cancel (close dialog)</AlertDialog.Cancel
>
<AlertDialog.Action type="submit">Yes (submit form)</AlertDialog.Action
>
</form>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
폼 안에서 사용하기(Inside a Form)
AlertDialog를 폼 안에서 사용한다면 Portal을 비활성화하거나 AlertDialog 구조에 포함하지 않아야 해요. 포털이 다이얼로그 콘텐츠를 폼 바깥에 렌더링하면 폼이 제대로 제출되지 않기 때문이에요.
API 참조(API Reference)
AlertDialog.Root
경고 다이얼로그의 상태를 설정하고 관리하는 데 쓰는 루트 컴포넌트예요.
| Property | Type | Description | Details |
|---|---|---|---|
open $bindable |
boolean |
The open state of the component.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 |
AlertDialog.Trigger
누르면 경고 다이얼로그를 여는 요소예요.
| Property | Type | Description | Details |
|---|---|---|---|
ref $bindable |
HTMLButtonElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-state |
enum - 'open' | 'closed' |
The state of the alert dialog. | |
data-alert-dialog-trigger |
'' |
Present on the trigger element. |
AlertDialog.Content
경고 다이얼로그 모달 안에 표시되는 콘텐츠예요.
| Property | Type | Description | Details |
|---|---|---|---|
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' |
|
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' |
|
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 |
|
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 |
|
restoreScrollDelay |
number |
The delay in milliseconds before the scrollbar is restored after closing the dialog. This is only applicable when using the child snippet for custom transitions and preventScroll and forceMount are true. You should set this to a value greater than the transition duration to prevent content from shifting during the transition.Default: 0 |
|
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: Record<string, unknown> 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 state of the alert dialog. | |
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-alert-dialog-content |
'' |
Present on the content element. | |
data-nested-open |
'' |
Present when one or more nested dialogs are open within this dialog. Can be used to style parent dialogs differently when children are open. | |
data-nested |
'' |
Present when the dialog is a nested dialog, useful for hiding the overlay of nested dialogs to avoid overlapping with the root dialog's overlay. |
| CSS Variable | Description | Details |
|---|---|---|
--bits-dialog-depth |
The nesting depth of the dialog (0 for root dialogs, 1 for first nested, etc.). | |
--bits-dialog-nested-count |
The number of currently open nested dialogs within this dialog. Updates reactively as nested dialogs open and close. |
AlertDialog.Overlay
경고 다이얼로그가 열려 있을 때 body를 덮는 오버레이예요.
| Property | Type | Description | Details |
|---|---|---|---|
forceMount |
boolean |
Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animation library for the content.Default: false |
|
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: Record<string, unknown> 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 state of the alert dialog. | |
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-alert-dialog-overlay |
'' |
Present on the overlay element. | |
data-nested-open |
'' |
Present when one or more nested dialogs are open within this dialog. Can be used to style parent dialogs differently when children are open. | |
data-nested |
'' |
Present when the dialog is a nested dialog, useful for hiding the overlay of nested dialogs to avoid overlapping with the root dialog's overlay. |
| CSS Variable | Description | Details |
|---|---|---|
--bits-dialog-depth |
The nesting depth of the dialog (0 for root dialogs, 1 for first nested, etc.). | |
--bits-dialog-nested-count |
The number of currently open nested dialogs within this dialog. Updates reactively as nested dialogs open and close. |
AlertDialog.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 |
AlertDialog.Action
경고 다이얼로그 안에서 동작을 수행하는 버튼이에요. 이 버튼은 기본적으로 다이얼로그를 닫지 않아요. 자세한 내용은 폼 제출(Form Submission) 문서를 참고하세요.
| Property | Type | Description | Details |
|---|---|---|---|
ref $bindable |
HTMLButtonElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-alert-dialog-action |
'' |
Present on the action element. |
AlertDialog.Cancel
동작을 수행하지 않고 경고 다이얼로그를 닫는 데 쓰는 버튼이에요.
| Property | Type | Description | Details |
|---|---|---|---|
ref $bindable |
HTMLButtonElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-alert-dialog-cancel |
'' |
Present on the cancel element. |
AlertDialog.Title
경고 다이얼로그의 접근 가능한 제목이에요.
| Property | Type | Description | Details |
|---|---|---|---|
level |
union - 1 | 2 | 3 | 4 | 5 | 6 |
The heading level of the title. This will be set as the aria-level attribute.Default: 3 |
|
ref $bindable |
HTMLDivElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-alert-dialog-title |
'' |
Present on the title element. |
AlertDialog.Description
경고 다이얼로그의 접근 가능한 설명이에요.
| 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-alert-dialog-description |
'' |
Present on the description element. |
더 알아보기 (Learn more)
경고 다이얼로그는 확인 흐름이 필요한 모달이고, 보다 일반적인 모달이 필요하다면 다이얼로그(Dialog) 컴포넌트를 살펴보세요. 중첩 다이얼로그나 상태 관리는 State Management 문서에서 더 자세히 다뤄요.