본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

@atlaskit/modal-dialog — 모달 다이얼로그

원문 보기 위키 갱신

중요한 콘텐츠를 위한 모달 다이얼로그 컴포넌트예요. 사용자가 즉시 응답해야 하는 작업이나 중요한 메시지를 표시할 때 사용해요.

출처: 문서

본문

중요한 콘텐츠를 위한 모달 다이얼로그 컴포넌트예요.

  • 키워드: modal, dialog, confirmation, popup, overlay, focused, interaction, layer
  • 카테고리: overlay
  • 상태: general-availability

예시

import React, { Fragment, useCallback, useState } from 'react';
import Button from '@atlaskit/button/default/button';
import ModalBody from '@atlaskit/modal-dialog/modal-body';
import Modal from '@atlaskit/modal-dialog/modal-dialog';
import ModalFooter from '@atlaskit/modal-dialog/modal-footer';
import ModalHeader from '@atlaskit/modal-dialog/modal-header';
import ModalTitle from '@atlaskit/modal-dialog/modal-title';
import ModalTransition from '@atlaskit/modal-dialog/modal-transition';
import { Text } from '@atlaskit/primitives/compiled/text';
export default function Example(): React.JSX.Element {
	const [isOpen, setIsOpen] = useState(false);
	const openModal = useCallback(() => setIsOpen(true), []);
	const closeModal = useCallback(() => setIsOpen(false), []);
	return (
		<Fragment>
			<Button aria-haspopup="dialog" appearance="primary" onClick={openModal}>
				Open modal
			</Button>
			<ModalTransition>
				{isOpen && (
					<Modal onClose={closeModal}>
						<ModalHeader hasCloseButton>
							<ModalTitle>Duplicate this page</ModalTitle>
						</ModalHeader>
						<ModalBody>
							Duplicating this page will make it a child page of{' '}
							<Text weight="bold">Search - user exploration</Text>, in the{' '}
							<Text weight="bold">Search & Smarts</Text> space.
						</ModalBody>
						<ModalFooter>
							<Button appearance="subtle" onClick={closeModal}>
								Cancel
							</Button>
							<Button appearance="primary" onClick={closeModal}>
								Duplicate
							</Button>
						</ModalFooter>
					</Modal>
				)}
			</ModalTransition>
		</Fragment>
	);
}

Props

Prop Type Description
autoFocus RefObject<HTMLElement> Pass an element ref to focus on a specific element on load
children string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal Contents of the modal dialog
focusLockAllowlist (element: HTMLElement) => boolean Callback function which lets you allowlist nodes so they can be interacted with outside of the focus lock
height string | number Height of the modal dialog
isBlanketHidden boolean Will remove the blanket tinted background color
label string The label of the modal dialog that is announced to users of assistive
technology
onClose (e: KeyboardOrMouseEvent, analyticEvent: UIAnalyticsEvent) => void Callback function called when the modal dialog is requesting to be closed
onCloseComplete (element: HTMLElement) => void Callback function called when the modal dialog has finished closing
onOpenComplete (node: HTMLElement, isAppearing: boolean) => void Callback function called when the modal dialog has finished opening
onStackChange (stackIndex: number) => void Callback function called when the modal changes position in the stack
shouldCloseOnOverlayClick boolean Calls onClose when clicking the blanket behind the modal dialog
shouldReturnFocus boolean | RefObject<HTMLElement> ReturnFocus controls what happens when the user exits
focus lock mode
shouldScrollInViewport boolean Will set the scroll boundary to the viewport
stackIndex number The stackIndex is a reference to the position (index) of the calling dialog in a modal dialog stack
width string | number Width of the modal dialog

사용 지침

  • 즉각적인 응답이 필요한 작업이나, 응답을 강제해야 하는 중요/경고 상황에 사용해요. 닫을 때까지 화면을 막아요
  • 드물게 사용하세요 — 모달은 사용성을 침해해요
  • 모달 하나당 작업 하나예요. 상호작용을 제한하고, 중첩 모달은 피하세요 (접근성 문제)
  • 구조: 헤더(h1 제목), 닫기 버튼, 본문, 기본 + 취소/닫기 버튼이 있는 푸터
  • 푸터: 기본 버튼은 보조 버튼의 오른쪽에 두고, 여러 닫기 방법(닫기 버튼, Esc, 블랭킷 클릭, Cancel/Close)을 제공해요
  • 작은 정보 + 컨트롤에는 Popup, 온보딩에는 Spotlight, 알림/작업에는 Inline message를 사용해요

콘텐츠 지침

  • 명확하고 설명적인 제목을 사용해요
  • 기본 버튼 라벨은 모달 제목을 반영해야 해요
  • 버튼 라벨에는 동작 동사를 사용해요
  • 콘텐츠를 단일 작업이나 메시지에 집중시켜요
  • 모든 텍스트는 문장형 대소문자(sentence case)를 사용해요

접근성 지침

  • 모달에는 제목이 있어야 해요. title 컴포넌트, useModal의 titleId, 또는 label을 사용해요 (시각적 제목이 없을 땐 피하세요)
  • 닫기 버튼은 필수예요 (드문 경우 제외 — a11y 팀에 문의하세요)
  • 심각도 표현을 색 하나에만 의존하지 말고, 아이콘에는 접근 가능한 라벨을 제공해요
  • 포커스 순서: 1) 닫기(또는 제목, 컨테이너), 2) 첫 번째 포커스 가능 요소, 3) 보조 버튼, 4) 기본 버튼, 5) 닫을 때 트리거로 포커스 반환
  • 닫기 방법: 닫기 버튼, Esc, 블랭킷 클릭, 푸터의 Cancel/Close
  • 모달 콘텐츠가 스크린 리더에 안내되도록 해요
  • 키보드 내비게이션과 escape 키를 지원해요
  • 모달이 열려 있는 동안 포커스를 모달 안에 유지해요

CloseButton component

커스텀 모달 헤더에서 사용하는 접근 가능한 닫기 버튼이에요. 사용자가 모달을 닫을 명확한 방법을 갖도록 보장해요.

  • 키워드: modal, close, button, dismiss
  • 카테고리: overlay
  • 상태: general-availability

예시

import React, { Fragment, useCallback, useState } from 'react';
import Button from '@atlaskit/button/default/button';
import { cssMap } from '@atlaskit/css';
import Heading from '@atlaskit/heading/heading';
import { CloseButton } from '@atlaskit/modal-dialog/close-button';
import { useModal } from '@atlaskit/modal-dialog/hooks';
import ModalBody from '@atlaskit/modal-dialog/modal-body';
import Modal from '@atlaskit/modal-dialog/modal-dialog';
import ModalFooter from '@atlaskit/modal-dialog/modal-footer';
import ModalTransition from '@atlaskit/modal-dialog/modal-transition';
import { Box } from '@atlaskit/primitives/compiled/box';
import { Text } from '@atlaskit/primitives/compiled/text';
const styles = cssMap({
	header: {
		display: 'flex',
		alignItems: 'center',
		justifyContent: 'space-between',
		flexDirection: 'row-reverse',
	},
});
const CustomHeader = () => {
	const { onClose, titleId } = useModal();
	return (
		<Box xcss={styles.header} padding="space.300">
			{/* We have the close button first in the DOM and then are reversing it
			using the flex styles to ensure that it is focused as the first
			interactive element in the modal, *before* any other relevant content
			inside the modal. This ensures users of assistive technology get all
			relevant content. */}
			<CloseButton onClick={onClose} />
			<Heading as="h1" size="medium" id={titleId}>
				Custom modal header
			</Heading>
		</Box>
	);
};
export default function Example(): React.JSX.Element {
	const [isOpen, setIsOpen] = useState(false);
	const openModal = useCallback(() => setIsOpen(true), []);
	const closeModal = useCallback(() => setIsOpen(false), []);
	return (
		<Fragment>
			<Button aria-haspopup="dialog" appearance="primary" onClick={openModal}>
				Open modal
			</Button>
			<ModalTransition>
				{isOpen && (
					// This is fixed in the custom header
					<Modal onClose={closeModal}>
						<CustomHeader />
						<ModalBody>
							<Text as="p">
								If you wish to customise a modal dialog, it accepts any valid React element as
								children.
							</Text>
							<Text as="p">
								Modal header accepts any valid React element as children, so you can use modal title
								in conjunction with other elements like an exit button in the top right.
							</Text>
							<Text as="p">
								Modal footer accepts any valid React element as children. For example, you can add
								an avatar in the footer. For very custom use cases, you can achieve the same thing
								without modal footer.
							</Text>
						</ModalBody>
						<ModalFooter>
							<Button appearance="subtle">About modals</Button>
							<Button appearance="primary" onClick={closeModal}>
								Close
							</Button>
						</ModalFooter>
					</Modal>
				)}
			</ModalTransition>
		</Fragment>
	);
}

Props

Prop Type Description
label string The accessible name to give to the close button
onBlur (event: React.FocusEvent<HTMLButtonElement, Element>) => void The onBlur handler for the close button
onClick (e: KeyboardOrMouseEvent, analyticEvent: UIAnalyticsEvent) => void The same close handler you give to the top-level modal component (required)

사용 지침

  • hasCloseButton 없이 ModalHeader를 커스터마이즈할 때 사용해요
  • 올바른 포커스 순서를 위해 DOM에서 CloseButton을 첫 번째로 렌더링해요
  • 닫기가 오른쪽에 나타나야 한다면 Flex에 row-reverse를 사용해요
  • 커스텀 접근 가능 이름을 위해 label prop을 제공해요

접근성 지침

  • 모달에는 닫기 버튼이 필요해요 (드문 예외는 a11y 팀에 문의하세요)
  • 닫기 버튼이 키보드로 접근 가능해야 해요

ModalBody component

모달 다이얼로그의 주요 콘텐츠 영역이에요.

  • 키워드: modal, body, content
  • 카테고리: overlay
  • 상태: general-availability

예시

import React, { Fragment, useCallback, useState } from 'react';
import Button from '@atlaskit/button/default/button';
import ModalBody from '@atlaskit/modal-dialog/modal-body';
import Modal from '@atlaskit/modal-dialog/modal-dialog';
import ModalFooter from '@atlaskit/modal-dialog/modal-footer';
import ModalHeader from '@atlaskit/modal-dialog/modal-header';
import ModalTitle from '@atlaskit/modal-dialog/modal-title';
import ModalTransition from '@atlaskit/modal-dialog/modal-transition';
import { Text } from '@atlaskit/primitives/compiled/text';
export default function Example(): React.JSX.Element {
	const [isOpen, setIsOpen] = useState(false);
	const openModal = useCallback(() => setIsOpen(true), []);
	const closeModal = useCallback(() => setIsOpen(false), []);
	return (
		<Fragment>
			<Button aria-haspopup="dialog" appearance="primary" onClick={openModal}>
				Open modal
			</Button>
			<ModalTransition>
				{isOpen && (
					<Modal onClose={closeModal}>
						<ModalHeader hasCloseButton>
							<ModalTitle>Duplicate this page</ModalTitle>
						</ModalHeader>
						<ModalBody>
							Duplicating this page will make it a child page of{' '}
							<Text weight="bold">Search - user exploration</Text>, in the{' '}
							<Text weight="bold">Search & Smarts</Text> space.
						</ModalBody>
						<ModalFooter>
							<Button appearance="subtle" onClick={closeModal}>
								Cancel
							</Button>
							<Button appearance="primary" onClick={closeModal}>
								Duplicate
							</Button>
						</ModalFooter>
					</Modal>
				)}
			</ModalTransition>
		</Fragment>
	);
}

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Children of modal dialog footer (required)
hasInlinePadding boolean Determines whether inline padding will be applied

사용 지침

  • 헤더와 푸터 사이의 주요 콘텐츠에 사용해요
  • children으로 유효한 React 엘리먼트를 모두 받아요
  • 콘텐츠가 뷰포트를 초과할 때 오버플로와 스크롤을 처리해요

콘텐츠 지침

  • 콘텐츠를 단일 작업에 집중시켜요
  • 명확하고 읽기 쉬운 콘텐츠를 사용해요

ModalFooter component

모달 다이얼로그의 푸터 영역으로, 보통 동작 버튼을 포함해요.

  • 키워드: modal, footer, actions, buttons
  • 카테고리: overlay
  • 상태: general-availability

예시

/**
 * @jsxRuntime classic
 * @jsx jsx
 */
import { Fragment, useCallback, useState } from 'react';
import Avatar from '@atlaskit/avatar/avatar';
import Button from '@atlaskit/button/default/button';
import { cssMap, jsx } from '@atlaskit/css';
import ModalBody from '@atlaskit/modal-dialog/modal-body';
import Modal from '@atlaskit/modal-dialog/modal-dialog';
import ModalFooter from '@atlaskit/modal-dialog/modal-footer';
import ModalHeader from '@atlaskit/modal-dialog/modal-header';
import ModalTitle from '@atlaskit/modal-dialog/modal-title';
import ModalTransition from '@atlaskit/modal-dialog/modal-transition';
import { Flex } from '@atlaskit/primitives/compiled/flex';
import { Text } from '@atlaskit/primitives/compiled/text';
const styles = cssMap({
	footer: { flex: '1' },
});
export default function Example(): JSX.Element {
	const [isOpen, setIsOpen] = useState(false);
	const openModal = useCallback(() => setIsOpen(true), []);
	const closeModal = useCallback(() => setIsOpen(false), []);
	return (
		<Fragment>
			<Button aria-haspopup="dialog" appearance="primary" onClick={openModal}>
				Open modal
			</Button>
			<ModalTransition>
				{isOpen && (
					<Modal onClose={closeModal}>
						<ModalHeader hasCloseButton>
							<ModalTitle>Default modal footer</ModalTitle>
						</ModalHeader>
						<ModalBody>
							<Text as="p">
								If you wish to customise a modal dialog, it accepts any valid React element as
								children.
							</Text>
							<Text as="p">
								Modal header accepts any valid React element as children, so you can use modal title
								in conjunction with other elements like an exit button in the top right.
							</Text>
							<Text as="p">
								Modal footer accepts any valid React element as children. For example, you can add
								an avatar in the footer. For very custom use cases, you can achieve the same thing
								without modal footer.
							</Text>
						</ModalBody>
						<ModalFooter>
							<Flex xcss={styles.footer} justifyContent="space-between">
								<Flex alignItems="center" gap="space.100">
									<Avatar
										size="small"
										src="https://pbs.twimg.com/profile_images/803832195970433027/aaoG6PJI_400x400.jpg"
									/>
									<Text as="p">Hey there!</Text>
								</Flex>
								<Button appearance="primary" onClick={closeModal}>
									Close
								</Button>
							</Flex>
						</ModalFooter>
					</Modal>
				)}
			</ModalTransition>
		</Fragment>
	);
}

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Children of modal dialog footer

사용 지침

  • 기본 동작과 보조 동작에 사용해요
  • 기본 버튼은 보조 버튼의 오른쪽에 두어요
  • 닫기 위해 Cancel/Close를 포함해요
  • 커스텀 레이아웃을 위해 유효한 React 엘리먼트를 모두 받아요

콘텐츠 지침

  • 기본 버튼 라벨은 모달 제목을 반영해야 해요
  • 버튼 라벨에는 동작 동사를 사용해요

ModalHeader component

모달 다이얼로그의 헤더 영역으로, 보통 제목과 선택적 닫기 버튼을 포함해요.

  • 키워드: modal, header, title, close
  • 카테고리: overlay
  • 상태: general-availability

예시

import React, { Fragment, useCallback, useState } from 'react';
import Button from '@atlaskit/button/default/button';
import ModalBody from '@atlaskit/modal-dialog/modal-body';
import Modal from '@atlaskit/modal-dialog/modal-dialog';
import ModalFooter from '@atlaskit/modal-dialog/modal-footer';
import ModalHeader from '@atlaskit/modal-dialog/modal-header';
import ModalTitle from '@atlaskit/modal-dialog/modal-title';
import ModalTransition from '@atlaskit/modal-dialog/modal-transition';
import { Text } from '@atlaskit/primitives/compiled/text';
export default function Example(): React.JSX.Element {
	const [isOpen, setIsOpen] = useState(false);
	const openModal = useCallback(() => setIsOpen(true), []);
	const closeModal = useCallback(() => setIsOpen(false), []);
	return (
		<Fragment>
			<Button aria-haspopup="dialog" appearance="primary" onClick={openModal}>
				Open modal
			</Button>
			<ModalTransition>
				{isOpen && (
					<Modal onClose={closeModal}>
						<ModalHeader hasCloseButton>
							<ModalTitle>Default modal header</ModalTitle>
						</ModalHeader>
						<ModalBody>
							<Text as="p">
								If you wish to customise a modal dialog, it accepts any valid React element as
								children.
							</Text>
							<Text as="p">
								Modal header accepts any valid React element as children, so you can use modal title
								in conjunction with other elements like an exit button in the top right.
							</Text>
							<Text as="p">
								Modal footer accepts any valid React element as children. For example, you can add
								an avatar in the footer. For very custom use cases, you can achieve the same thing
								without modal footer.
							</Text>
						</ModalBody>
						<ModalFooter>
							<Button appearance="subtle">About modals</Button>
							<Button appearance="primary" onClick={closeModal}>
								Close
							</Button>
						</ModalFooter>
					</Modal>
				)}
			</ModalTransition>
		</Fragment>
	);
}

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Children of modal dialog header
hasCloseButton boolean Shows a close button at the end of the header

사용 지침

  • Modal의 첫 번째 자식으로 사용해요
  • 표준 닫기 기능에는 hasCloseButton prop을 사용해요
  • 접근성을 위해 헤더에 ModalTitle 또는 이에 상응하는 요소가 있게 해요
  • 커스텀 헤더에서는 DOM에서 CloseButton을 첫 번째 요소로 두어요

콘텐츠 지침

  • 명확하고 설명적인 제목을 사용해요
  • 헤더 콘텐츠를 집중되게 유지해요

ModalTitle component

모달 다이얼로그의 제목 요소예요. 접근성을 위해 h1로 렌더링돼요.

  • 키워드: modal, title, heading
  • 카테고리: overlay
  • 상태: general-availability

예시

import React, { Fragment, useCallback, useState } from 'react';
import Button from '@atlaskit/button/default/button';
import ModalBody from '@atlaskit/modal-dialog/modal-body';
import Modal from '@atlaskit/modal-dialog/modal-dialog';
import ModalFooter from '@atlaskit/modal-dialog/modal-footer';
import ModalHeader from '@atlaskit/modal-dialog/modal-header';
import ModalTitle from '@atlaskit/modal-dialog/modal-title';
import ModalTransition from '@atlaskit/modal-dialog/modal-transition';
import { Text } from '@atlaskit/primitives/compiled/text';
export default function Example(): React.JSX.Element {
	const [isOpen, setIsOpen] = useState(false);
	const openModal = useCallback(() => setIsOpen(true), []);
	const closeModal = useCallback(() => setIsOpen(false), []);
	return (
		<Fragment>
			<Button aria-haspopup="dialog" appearance="primary" onClick={openModal}>
				Open modal
			</Button>
			<ModalTransition>
				{isOpen && (
					<Modal onClose={closeModal}>
						<ModalHeader hasCloseButton>
							<ModalTitle>Duplicate this page</ModalTitle>
						</ModalHeader>
						<ModalBody>
							Duplicating this page will make it a child page of{' '}
							<Text weight="bold">Search - user exploration</Text>, in the{' '}
							<Text weight="bold">Search & Smarts</Text> space.
						</ModalBody>
						<ModalFooter>
							<Button appearance="subtle" onClick={closeModal}>
								Cancel
							</Button>
							<Button appearance="primary" onClick={closeModal}>
								Duplicate
							</Button>
						</ModalFooter>
					</Modal>
				)}
			</ModalTransition>
		</Fragment>
	);
}

Props

Prop Type Description
appearance "warning" | "danger" Appearance of the modal that changes the color of the primary action and adds an icon to the title
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal Children of modal dialog header
isMultiline boolean When true will allow the title to span multiple lines

사용 지침

  • 모달 제목에는 ModalHeader 안에서 사용해요
  • 접근성을 위해 모달에는 제목이 있어야 해요
  • children으로 유효한 React 엘리먼트를 모두 지원해요

콘텐츠 지침

  • 명확하고 설명적인 제목을 사용해요
  • 문장형 대소문자(sentence case)를 사용해요

ModalTransition component

모달 콘텐츠에 진입/퇴장 전환을 제공하는 래퍼예요.

  • 키워드: modal, transition, animation
  • 카테고리: overlay
  • 상태: general-availability

예시

import React, { Fragment, useCallback, useState } from 'react';
import Button from '@atlaskit/button/default/button';
import ModalBody from '@atlaskit/modal-dialog/modal-body';
import Modal from '@atlaskit/modal-dialog/modal-dialog';
import ModalFooter from '@atlaskit/modal-dialog/modal-footer';
import ModalHeader from '@atlaskit/modal-dialog/modal-header';
import ModalTitle from '@atlaskit/modal-dialog/modal-title';
import ModalTransition from '@atlaskit/modal-dialog/modal-transition';
import { Text } from '@atlaskit/primitives/compiled/text';
export default function Example(): React.JSX.Element {
	const [isOpen, setIsOpen] = useState(false);
	const openModal = useCallback(() => setIsOpen(true), []);
	const closeModal = useCallback(() => setIsOpen(false), []);
	return (
		<Fragment>
			<Button aria-haspopup="dialog" appearance="primary" onClick={openModal}>
				Open modal
			</Button>
			<ModalTransition>
				{isOpen && (
					<Modal onClose={closeModal}>
						<ModalHeader hasCloseButton>
							<ModalTitle>Duplicate this page</ModalTitle>
						</ModalHeader>
						<ModalBody>
							Duplicating this page will make it a child page of{' '}
							<Text weight="bold">Search - user exploration</Text>, in the{' '}
							<Text weight="bold">Search & Smarts</Text> space.
						</ModalBody>
						<ModalFooter>
							<Button appearance="subtle" onClick={closeModal}>
								Cancel
							</Button>
							<Button appearance="primary" onClick={closeModal}>
								Duplicate
							</Button>
						</ModalFooter>
					</Modal>
				)}
			</ModalTransition>
		</Fragment>
	);
}

Props

Prop Type Description
children string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | React.ReactPortal Children can be any valid react node

사용 지침

  • 애니메이션된 열기/닫기를 위해 Modal을 ModalTransition으로 감싸요
  • 모달 표시 여부가 상태로 제어될 때 사용해요
  • children은 표시되면 마운트되고 닫히면 언마운트돼요

더 알아보기 (Learn more)