Dialog
Dialog는 오버레이 창에 콘텐츠를 표시하는 컨테이너 컴포넌트예요. 모달, 드래그, 최대화 등 다양한 대화 상자 형태를 지원하죠.
출처: 문서
본문
Dialog는 오버레이 창에 콘텐츠를 표시하는 컨테이너예요.
설치 (Installation)
Shadcn CLI Manual ```bash npx shadcn@latest add https://primereact.dev/r/dialog.json ``` 프로젝트에 다음 코드를 복사해서 붙여넣으세요. 가져오기(import) 경로를 프로젝트 설정에 맞게 업데이트하세요.사용법 (Usage)
import { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogHeaderActions, DialogMaximizable, DialogPopup, DialogPortal, DialogPositioner, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
<Dialog>
<DialogTrigger />
<DialogPortal>
<DialogBackdrop />
<DialogPositioner>
<DialogPopup>
<DialogHeader>
<DialogTitle />
<DialogHeaderActions>
<DialogMaximizable />
<DialogClose />
</DialogHeaderActions>
</DialogHeader>
<DialogContent />
<DialogFooter />
</DialogPopup>
</DialogPositioner>
</DialogPortal>
</Dialog>
예시 (Examples)
기본 (Basic)
드래그 가능 (Draggable)
draggable prop이 활성화되면 헤더를 드래그해 대화 상자의 위치를 변경할 수 있어요.
위치 (Position)
대화 상자의 위치는 position 속성으로 커스터마이즈할 수 있어요. 사용 가능한 값은 top, top-left, top-right, bottom, bottom-left, bottom-right, left, right, center예요.
최대화 (Maximizable)
Dialog.Maximizable 버튼을 클릭하면 대화 상자를 최대화할 수 있어요.
전체 화면 (Full Screen)
fullScreen prop은 대화 상자를 최대화된 모드로 엽니다. Dialog.Maximizable 버튼이 없으면 대화 상자는 닫힐 때까지 전체 화면을 유지해요.
모달 (Modal)
페이지와의 상호작용을 차단하는 백드롭이 있는 모달 대화 상자예요. modal과 dismissable이 모두 활성화되면 대화 상자 바깥을 클릭해 닫을 수 있어요.
모달 없이 (Without Modal)
모달 레이어가 없는 대화 상자예요. 페이지는 대화 상자 뒤에서 계속 상호작용할 수 있어요.
확인 (Confirmation)
경고 메시지와 동작 버튼이 있는 확인 대화 상자의 흔한 패턴이에요.
내부 스크롤 (Inside Scroll)
scrollBehavior가 inside로 설정되면 헤더와 푸터는 고정된 채 대화 상자의 콘텐츠 영역만 스크롤해요.
외부 스크롤 (Outside Scroll)
scrollBehavior가 outside로 설정되면 전체 대화 상자가 positioner 안에서 스크롤되어, 전체 대화 상자가 하나의 단위로 움직여요.
반응형 (Responsive)
Dialog 너비는 _DialogPopup_의 반응형 CSS 클래스를 사용해 다양한 화면 크기에 맞게 조정돼요.
접근성 (Accessibility)
화면 낭독기 (Screen Reader)
Dialog 컴포넌트는 dialog 역할과 함께 헤더 요소를 가리키는 aria-labelledby를 사용해요. 단 모든 속성은 루트 요소에 전달되므로, aria-labelledby로 이 기본 동작을 재정의할 수 있어요. 또한 포커스가 팝업 안에 유지되므로 aria-modal이 추가돼요.
트리거 요소에도 aria-expanded와 aria-controls가 명시적으로 처리돼요.
오버레이 키보드 지원 (Overlay Keyboard Support)
| Key | Function |
|---|---|
tab |
Moves focus to the next the focusable element within the dialog if modal is true. Otherwise, the focusable element in the page tab sequence. |
shift + tab |
Moves focus to the previous the focusable element within the dialog if modal is true. Otherwise, the focusable element in the page tab sequence. |
escape |
Closes the dialog if closeOnEscape is true. |
닫기 버튼 키보드 지원 (Close Button Keyboard Support)
| Key | Function |
|---|---|
enter |
Closes the dialog. |
space |
Closes the dialog. |