# Dialog
URL: /react/components/dialog
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/components/dialog.mdx
A dialog that floats in the center of the screen to capture the user's attention. Used to hold rich content such as forms or scrollable content with a title, body, footer, and close button.
사용 가능 버전: @seed-design/react@2.1.0, @seed-design/css@2.3.0
## Preview
```tsx
import { HStack, Text } from "@seed-design/react";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
import { ActionButton } from "seed-design/ui/action-button";
const DialogPreview = () => {
return (
Open Dialog
The body can hold content for users to review or an extra input form.
Cancel
OK
);
};
export default DialogPreview;
```
Use Alert Dialog if the purpose is to get user confirmation or warning.
## Installation
### Default
Includes a default Dialog component that floats in the center of the screen and holds a title, body, and footer.
- npm: npx @seed-design/cli@latest add ui:dialog
- pnpm: pnpm dlx @seed-design/cli@latest add ui:dialog
- yarn: yarn dlx @seed-design/cli@latest add ui:dialog
- bun: bun x @seed-design/cli@latest add ui:dialog
### Responsive
A responsive variant that automatically switches to Bottom Sheet based on viewport.
- npm: npx @seed-design/cli@latest add ui:responsive-dialog
- pnpm: pnpm dlx @seed-design/cli@latest add ui:responsive-dialog
- yarn: yarn dlx @seed-design/cli@latest add ui:responsive-dialog
- bun: bun x @seed-design/cli@latest add ui:responsive-dialog
## Props
### `DialogRoot`
### `DialogTrigger`
### `DialogContent`
### `DialogBody`
### `DialogFooter`
### `DialogAction`
### `ResponsiveDialogRoot`
## Examples
### Trigger
`` sets the `aria-haspopup="dialog"` attribute and automatically sets the `aria-expanded` attribute based on the Dialog's `open` state. This attribute is useful for assistive technologies like screen readers.
```tsx
import { HStack, Text } from "@seed-design/react";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
import { ActionButton } from "seed-design/ui/action-button";
const DialogTriggerExample = () => {
return (
Open
Trigger를 클릭하면 현재 화면 위에 Dialog가 열립니다.
취소
확인
);
};
export default DialogTriggerExample;
```
### Controlled
You can open and close the Dialog in ways other than Trigger. In this case, use the `open` prop to control the Dialog's state.
```tsx
import { HStack, Text } from "@seed-design/react";
import { useState } from "react";
import { ActionButton } from "seed-design/ui/action-button";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
} from "seed-design/ui/dialog";
const DialogControlled = () => {
const [open, setOpen] = useState(false);
return (
<>
setOpen(true)}>
열기
Labore do culpa dolore irure nisi dolor dolor laboris veniam ipsum excepteur
adipisicing laboris non quis. Velit ea ut minim. Magna dolore culpa velit incididunt
consequat sint. Fugiat ad culpa labore dolore esse dolore ex aliquip duis aute aliquip
ad velit et.
취소
확인
>
);
};
export default DialogControlled;
```
### Size
You can change the Dialog's width by setting the `size` prop on ``. Supports `"medium"` (480px, default) and `"large"` (800px). On screens smaller than `md`, it takes 90% of the viewport width, and on `md` and above, the maximum width of each size is applied. The content height is limited to 80% of the viewport.
You can also directly control the width by passing `width` and `maxWidth` props to ``. Use this when you need flexible viewport-based width instead of preset sizes. Since a single value applies to all breakpoints, pass a breakpoint object like `width={{ md: "560px" }}` to maintain the default width for below `md` (90% of viewport).
```tsx
import { Flex, HStack, Text, VStack } from "@seed-design/react";
import { useState } from "react";
import { ActionButton } from "seed-design/ui/action-button";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
import { Slider } from "seed-design/ui/slider";
const DialogSize = () => {
const [width, setWidth] = useState(90);
const [maxWidth, setMaxWidth] = useState(640);
return (
Medium (480px)
기본 너비로 상세 정보와 주요 액션을 함께 제공합니다.
취소
확인
Large (800px)
넓은 다이얼로그에서 더 많은 폼 필드나 상세 콘텐츠를 다룹니다.
취소
확인
Custom (조절 가능)
뷰포트 너비에 따라 유동적으로 커지되 maxWidth로 최대 크기를 제한합니다.
setWidth(values[0])}
/>
setMaxWidth(values[0])}
/>
취소
확인
);
};
export default DialogSize;
```
### Body
`` makes the body area scrollable. When the body is long and scrolls, a divider appears below the header and a fade-out mask is applied at the bottom. The bottom fade mask and `padding-bottom` are applied only when the Body exceeds the viewport height and creates scroll. If the body is short and does not overflow, the mask is not applied so the last line is not blurred.
```tsx
import { HStack, Text, VStack } from "@seed-design/react";
import { ActionButton } from "seed-design/ui/action-button";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
const DialogBodyExample = () => {
return (
짧은 본문 (fade 없음)
내용이 짧아 스크롤이 없으면 하단 마스크가 적용되지 않아, 마지막 줄이 흐려지지
않습니다.
취소
확인
긴 본문 (fade 적용)
{Array.from({ length: 16 }, (_, index) => (
{index + 1}. Body가 넘치면 하단에 fade 마스크와 padding-bottom이 적용되고,
스크롤하면 헤더 아래에 구분선이 나타납니다.
))}
취소
확인
);
};
export default DialogBodyExample;
```
### Custom Body
You can directly control the body area by passing `paddingX`, `minHeight`, `maxHeight`, `justifyContent`, and `alignItems` props to ``. Use this to limit scroll height lower than the default cap (80% of viewport), fix height even with short content, or remove horizontal padding to stretch content to the edges.
```tsx
import { Box, Flex, HStack, Text, VStack } from "@seed-design/react";
import { ActionButton } from "seed-design/ui/action-button";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
const DialogCustomBody = () => {
return (
maxHeight 200px
{Array.from({ length: 12 }, (_, index) => (
{index + 1}. 본문이 200px을 넘으면 그 안에서 스크롤됩니다.
))}
취소
확인
minHeight + 가운데 정렬
아직 항목이 없습니다
취소
추가
paddingX 0
가장자리까지 닿는 영역입니다
취소
확인
);
};
export default DialogCustomBody;
```
### Show Close Button
You can show the close button in the top right by passing the `showCloseButton` prop to ``. The default value is `true`.
```tsx
import { Flex, HStack, Text } from "@seed-design/react";
import { ActionButton } from "seed-design/ui/action-button";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
const DialogShowCloseButton = () => {
return (
닫기 버튼 있음
기본적으로 우측 상단에 닫기 버튼이 표시됩니다.
취소
확인
닫기 버튼 없음
닫기 버튼을 숨길 때는 본문이나 푸터에 닫을 수 있는 액션을 제공하세요.
취소
확인
);
};
export default DialogShowCloseButton;
```
### Footer Layout
`DialogFooter` provides only flex layout, and button arrangement is directly composed with `VStack`, `HStack`, etc.
```tsx
import { HStack, Text, VStack } from "@seed-design/react";
import { ActionButton } from "seed-design/ui/action-button";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
const DialogFooterLayout = () => {
return (
Footer 레이아웃
DialogFooter는 flex 레이아웃만 제공합니다.
넓은 다이얼로그에서는 주요 액션을 우측에 가로로 정렬할 수 있습니다.
취소
확인
);
};
export default DialogFooterLayout;
```
### Prevent Close
If you call `e.preventDefault()` in `DialogAction`'s `onClick`, the dialog will not close.
```tsx
import { HStack } from "@seed-design/react";
import { useState } from "react";
import { ActionButton } from "seed-design/ui/action-button";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
import { Switch } from "seed-design/ui/switch";
const DialogPreventClose = () => {
const [preventClose, setPreventClose] = useState(true);
return (
열기
취소
{
if (preventClose) {
e.preventDefault();
}
}}
>
확인
);
};
export default DialogPreventClose;
```
### `onOpenChange` Details
`details` is provided as the second argument to `onOpenChange`.
#### `reason`
**When opening** (`open: true`)
- `"trigger"`: opened via `DialogTrigger`
**When closing** (`open: false`)
- `"closeButton"`: closed via `DialogAction` or the top-right close button
- `"escapeKeyDown"`: ESC key used
- `"interactOutside"`: click outside area
- `DialogRoot` defaults to `closeOnInteractOutside={false}`. `interactOutside` can only occur when this option is set to `true`.
- `"cascadeDismiss"`: cascading close due to parent layer closing
```tsx
import { HStack, Text, VStack } from "@seed-design/react";
import { useState } from "react";
import { ActionButton } from "seed-design/ui/action-button";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
import { Switch } from "seed-design/ui/switch";
const DialogOnOpenChangeReason = () => {
const [open, setOpen] = useState(false);
const [openReason, setOpenReason] = useState(null);
const [closeReason, setCloseReason] = useState(null);
const [closeOnInteractOutside, setCloseOnInteractOutside] = useState(false);
return (
{
setOpen(open);
(open ? setOpenReason : setCloseReason)(details?.reason ?? null);
}}
>
열기
ESC 키를 누르거나 우측 상단 닫기 버튼, 하단 버튼을 눌러 닫아보세요. 아래 스위치를 켠
뒤 바깥 영역을 누르면 interactOutside 이유로 닫힙니다.
취소
확인
마지막 열림 이유: {openReason ?? "-"}
마지막 닫힘 이유: {closeReason ?? "-"}
);
};
export default DialogOnOpenChangeReason;
```
#### Confirm Before Close
If you want to prevent accidentally closing content being written, keep `open` in a controlled state and show a confirmation Alert Dialog while maintaining `open` for specific `reason` to ask the user.
```tsx
import { HStack, ResponsivePair, Text, VStack } from "@seed-design/react";
import { useState } from "react";
import { ActionButton } from "seed-design/ui/action-button";
import {
AlertDialogAction,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogRoot,
AlertDialogTitle,
} from "seed-design/ui/alert-dialog";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
type DialogRootProps,
} from "seed-design/ui/dialog";
import { Switch } from "seed-design/ui/switch";
const closeReasons = [
"closeButton",
"escapeKeyDown",
"interactOutside",
] as const satisfies NonNullable<
Parameters>[1]
>["reason"][];
const confirmReasonLabels = {
closeButton: "닫기 버튼으로 닫을 때 확인 (closeButton)",
escapeKeyDown: "ESC 키로 닫을 때 확인 (escapeKeyDown)",
interactOutside: "바깥 클릭으로 닫을 때 확인 (interactOutside)",
} as const satisfies Record<(typeof closeReasons)[number], string>;
const DialogConfirmBeforeClose = () => {
const [open, setOpen] = useState(false);
const [confirmOpen, setConfirmOpen] = useState(false);
const [closeOnInteractOutside, setCloseOnInteractOutside] = useState(true);
const [confirmReasons, setConfirmReasons] = useState<
Record<(typeof closeReasons)[number], boolean>
>({ closeButton: true, escapeKeyDown: true, interactOutside: true });
return (
<>
{
if (nextOpen) {
setOpen(true);
return;
}
const reason = closeReasons.find((reason) => reason === details?.reason);
if (reason && confirmReasons[reason]) {
setConfirmOpen(true);
return;
}
setOpen(false);
}}
>
작성 폼 열기
닫으려는 reason별로 확인 다이얼로그 띄우기
{closeReasons.map((reason) => (
setConfirmReasons((prev) => ({ ...prev, [reason]: checked }))
}
/>
))}
취소
저장
정말 닫을까요?
작성 중인 내용은 저장되지 않습니다.
setConfirmOpen(false)}>
계속 작성
{
setConfirmOpen(false);
setOpen(false);
}}
>
닫기
>
);
};
export default DialogConfirmBeforeClose;
```
### Portalled
Portal is rendered to `document.body` by default.
```tsx
import { HStack, Portal, Text } from "@seed-design/react";
import { ActionButton } from "seed-design/ui/action-button";
import {
DialogAction,
DialogBody,
DialogContent,
DialogFooter,
DialogRoot,
DialogTrigger,
} from "seed-design/ui/dialog";
const DialogPortalled = () => {
return (
// You can set z-index dialog with "--layer-index" custom property. useful for stackflow integration.
열기
Portal은 기본적으로 document.body에 렌더링됩니다.
취소
확인
);
};
export default DialogPortalled;
```
### Responsive
Using `ResponsiveDialog` automatically switches to Dialog for `md` and above and to Bottom Sheet for `sm` and below. Try reducing the viewport to see the switch in action. `onOpenChange` passes only the open state, and Root options that apply only to Dialog or Bottom Sheet are passed via `dialogRootProps` and `bottomSheetRootProps`.
```tsx
import { HStack, Text, useResponsiveDialogContext } from "@seed-design/react";
import { forwardRef } from "react";
import { ActionButton } from "seed-design/ui/action-button";
import {
ResponsiveDialogAction,
ResponsiveDialogBody,
ResponsiveDialogContent,
ResponsiveDialogFooter,
ResponsiveDialogRoot,
ResponsiveDialogTrigger,
type ResponsiveDialogFooterProps,
} from "seed-design/ui/responsive-dialog";
const Footer = forwardRef((props, ref) => {
const { shouldUseBottomSheet } = useResponsiveDialogContext();
return (
취소
확인
);
});
const DialogResponsive = () => {
return (
Open
md 이상에서는 화면 중앙의 Dialog로, sm 이하에서는 화면 하단에서 슬라이드되는 Bottom
Sheet로 표시됩니다.
);
};
export default DialogResponsive;
```