Dialog 컴포넌트
Dialog를 사용하면 모달이 아닌(non-modal) 상호작용을 제시할 수 있습니다. 페이지의 나머지 영역을 계속 사용할 수 있는 상태에서 사용자의 응답, 입력, 결정을 요청할 때 사용합니다. 이 페이지에서는 개발 가이드라인, 단위·통합 테스트 예제와 API, 일반 가이드라인, 기능, 작성 가이드라인, 접근성 가이드라인을 다룹니다.
출처: 문서
본문
Dialog를 사용하면 모달이 아닌 상호작용을 제시할 수 있습니다.
차단(blocking) 상호작용을 찾고 있나요? 사용자가 페이지로 돌아가기 전에 상호작용을 완료하거나 닫아야 한다면 Modal을 사용하세요.
이 컴포넌트의 API 속성은 여기에서 확인할 수 있습니다: API Properties
개발 가이드라인 (Development guidelines)
상태 관리 (State management)
Dialog 컴포넌트는 자신의 표시 여부를 관리하지 않습니다. 조건부로 렌더링하고 닫을 때 제거하세요.
테스트 유틸리티 클래스가 처음이라면 소개 문서에서 자세히 알아볼 수 있습니다.
단위 테스트 예제 (Unit testing examples)
대화상자 선택하기
import { render } from '@testing-library/react';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import Dialog from '@cloudscape-design/components/dialog';
describe('<Dialog />', () => {
it('renders the dialog component', () => {
const { container } = render(<Dialog />);
const wrapper = createWrapper(container);
expect(wrapper.findDialog()).toBeTruthy();
});
});
대화상자 슬롯 찾기
import Dialog from '@cloudscape-design/components/dialog';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import { render } from '@testing-library/react';
describe('<Dialog />', () => {
it('finds the header, header actions, content, footer, and dismiss button', () => {
const { container } = render(
<Dialog
header="Dialog header"
headerActions={Dialog header actions}
footer="Dialog footer"
i18nStrings={{ dismissAriaLabel: 'Close dialog' }}
onDismiss={() => {}}
>
Dialog content
</Dialog>
);
const wrapper = createWrapper(container);
const dialog = wrapper.findDialog()!;
expect(dialog.findHeader()!.getElement().textContent).toContain('Dialog header');
expect(dialog.findHeaderActions()!.getElement().textContent).toBe('Dialog header actions');
expect(dialog.findContent()!.getElement().textContent).toContain('Dialog content');
expect(dialog.findFooter()!.getElement().textContent).toContain('Dialog footer');
expect(dialog.findDismissButton()!.getElement()).toHaveAttribute('aria-label', 'Close dialog');
});
});
모든 대화상자 찾기
import Dialog from '@cloudscape-design/components/dialog';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import { render } from '@testing-library/react';
describe('<Dialog />', () => {
it('finds all dialogs on the page', () => {
const { container } = render(
<>
<Dialog header="First dialog" onDismiss={() => {}}>
First dialog content
</Dialog>
<Dialog header="Second dialog" onDismiss={() => {}}>
Second dialog content
</Dialog>
<Dialog header="Third dialog" onDismiss={() => {}}>
Third dialog content
</Dialog>
</>
);
const wrapper = createWrapper(container);
const allDialogs = wrapper.findAllDialogs();
expect(allDialogs).toHaveLength(3);
expect(allDialogs[0].findHeader()!.getElement().textContent).toBe('First dialog');
expect(allDialogs[1].findHeader()!.getElement().textContent).toBe('Second dialog');
expect(allDialogs[2].findHeader()!.getElement().textContent).toBe('Third dialog');
});
});
단위 테스트 API (Unit testing APIs)
DialogWrapper
| 이름(Name) | 반환 타입(Return type) | 설명(Description) | 매개변수(Parameters) |
|---|---|---|---|
| findContent | ElementWrapper | null | 대화상자의 콘텐츠 슬롯을 찾습니다. | - |
| findDismissButton | ButtonWrapper | null | 대화상자의 닫기 버튼을 찾습니다. | - |
| findFooter | ElementWrapper | null | 대화상자의 footer 슬롯을 찾습니다. | - |
| findHeader | ElementWrapper | null | 대화상자의 헤더 슬롯을 찾습니다. | - |
| findHeaderActions | ElementWrapper | null | 대화상자의 헤더 동작 슬롯을 찾습니다. | - |
통합 테스트 API (Integration testing APIs)
DialogWrapper
| 이름(Name) | 반환 타입(Return type) | 설명(Description) | 매개변수(Parameters) |
|---|---|---|---|
| findContent | ElementWrapper | 대화상자의 콘텐츠 슬롯을 찾습니다. | - |
| findDismissButton | ButtonWrapper | 대화상자의 닫기 버튼을 찾습니다. | - |
| findFooter | ElementWrapper | 대화상자의 footer 슬롯을 찾습니다. | - |
| findHeader | ElementWrapper | 대화상자의 헤더 슬롯을 찾습니다. | - |
| findHeaderActions | ElementWrapper | 대화상자의 헤더 동작 슬롯을 찾습니다. | - |
일반 가이드라인 (General guidelines)
권장 사항 (Do)
- 페이지의 나머지 영역을 계속 사용할 수 있을 때 사용자의 응답, 입력, 결정을 요청하려면 대화상자를 사용하세요. 계속하기 전에 사용자가 응답해야 한다면 대신 modal을 사용하세요.
- 대화상자를 그것이 참조하는 콘텐츠 옆에 배치하세요. 예: 생성형 AI 응답에 사용자의 권한 부여나 추가 정보가 필요할 때 prompt input 위에 배치하기.
권장하지 않는 사항 (Don't)
- 사용자에게 어떤 것도 요청하지 않는 아이템이나 산출물(artifact)을 표시하는 데 대화상자를 사용하지 마세요.
- 일련의 대화상자를 연쇄(chaining)하지 말고, 대화상자 안에서 대화상자를 열지 마세요. 대화상자에 다단계 흐름이 있다면 대화상자 안에서 compact pagination을 사용해 단계 사이를 탐색하세요.
기능 (Features)
-
헤더 (Header)
헤더를 사용해 사용자에게 무엇을 요청하는지 진술하세요.
-
헤더 동작 - 선택 사항 (Header actions - optional)
대화상자 자체와 관련된 컨트롤을 닫기 버튼 앞에 추가하세요. 예: 여러 페이지로 구성된 폼을 위한 compact pagination.
-
콘텐츠 (Content)
대화상자의 기본 콘텐츠 영역입니다.
-
footer - 선택 사항 (Footer - optional)
Submit , Allow , Skip 같은 요청을 확정(commit)하거나 취소하는 동작을 위한 영역입니다. 폼 컨트롤은 콘텐츠 영역에 있을 수 있지만, 작업을 확정하거나 취소하는 동작은 항상 footer에 속합니다. footer가 비어 있으면 표시되지 않습니다.
작성 가이드라인 (Writing guidelines)
일반 작성 가이드라인 (General writing guidelines)
-
문장형 대소문자(sentence case)를 사용하되, 고유명사와 브랜드 이름은 맥락에 맞게 대문자화를 유지하세요.
-
현재형 동사와 능동태를 사용하세요.
-
작성에서 please , thank you , 줄임표( ... ), 앰퍼샌드( & ), e.g. , i.e. , etc. 를 사용하지 마세요.
-
방향을 지시하는 표현은 피하세요.
- 예: above 대신 previous 를, below 대신 following 을 사용하세요.
-
기기 독립적인 표현을 사용하세요.
- 예: click 대신 choose 나 select 를 사용하세요.
접근성 가이드라인 (Accessibility guidelines)
일반 접근성 가이드라인 (General accessibility guidelines)
- 각 컴포넌트에 대한 대체 텍스트와 접근 가능한 리치 인터넷 애플리케이션(ARIA) 영역에 대한 지침을 따르세요.
- 애플리케이션의 언어 맥락에 맞춘 ARIA 라벨을 정의하세요.
- 역할(role)과 랜드마크(landmark)에 불필요한 마크업을 추가하지 마세요. 각 컴포넌트에 대한 지침을 따르세요.
- 논리적이고 예측 가능한 순서로 모든 사용 가능한 콘텐츠에 키보드 기능을 제공하세요. 정보의 흐름이 이해가 되어야 합니다.
컴포넌트별 가이드라인 (Component-specific guidelines)
역할과 라벨 (Roles and labels)
Dialog 컴포넌트는 role 속성을 dialog 로 설정하고 헤더를 접근 가능한 이름(accessible name)으로 사용합니다. 다른 역할이나 접근 가능한 이름을 추가하지 마세요.
대체 텍스트 (Alternative text)
i18nStrings.dismissAriaLabel 을 사용해 닫기 버튼에 대한 대체 텍스트를 제공하세요. 애플리케이션이 I18nProvider 를 사용할 때 이 문자열은 자동으로 제공됩니다.
키보드 상호작용 (Keyboard interaction)
Dialog가 열리면 포커스가 첫 번째 포커스 가능한 요소로 이동합니다. 헤더 동작이 있다면 포커스는 첫 번째 포커스 가능한 헤더 동작으로 이동합니다. 그렇지 않으면 닫기 버튼으로 이동합니다.
포커스는 트랩(trap)되지 않으므로 사용자는 Dialog와 주변 페이지 사이를 이동할 수 있습니다. Escape를 누르면 Dialog가 닫힙니다. Dialog가 닫히면 이전에 포커스된 요소가 여전히 존재한다면 그 요소로 포커스가 돌아갑니다.