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

Drawer — 드로어

원문 보기 위키 갱신

내장 포커스 트랩, 스크롤 잠금, 닫기 가능 배경(backdrop)을 갖춘 스타일 없는 슬라이드 인 패널 컴포넌트예요.

출처: 문서

본문

레이아웃과 스타일링을 완전히 제어하며 완전히 커스텀한 슬라이드 인 패널을 만들어 보세요.

기능 (Features)

  • 하위 컴포넌트를 갖춘 복합 컴포넌트 API: Root, Trigger, Portal, Backdrop, Popup, Header, Title, Close, Content, Footer
  • 다섯 가지 위치 모드: left, right, top, bottom, full
  • 열고 닫을 때 자동 포커스 관리를 하는 통합 포커스 트랩
  • 외부 클릭 감지가 있는 닫기 가능 Backdrop
  • blockScroll을 통한 스크롤 잠금 지원

사용법 (Usage)

import { Drawer } from 'primereact/drawer';
<Drawer.Root>
    <Drawer.Trigger></Drawer.Trigger>
    <Drawer.Portal>
        <Drawer.Backdrop />
        <Drawer.Popup>
            <Drawer.Header>
                <Drawer.Title></Drawer.Title>
                <Drawer.Close></Drawer.Close>
            </Drawer.Header>
            <Drawer.Content></Drawer.Content>
            <Drawer.Footer></Drawer.Footer>
        </Drawer.Popup>
    </Drawer.Portal>
</Drawer.Root>

동작 (Behavior)

모션 애니메이션 (Motion Animation)

<Drawer.Popup motionProps={{ name: 'p-drawer', appear: true }}>...</Drawer.Popup>

애니메이션 단계, CSS 변수, 숨김 전략은 Motion을 참고해요.

다형성 렌더링 (Polymorphic Rendering)

어느 하위 컴포넌트에서든 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.

<Drawer.Trigger as="div">...</Drawer.Trigger>

렌더 함수 children (Render Function Children)

하위 컴포넌트는 children으로 렌더 함수를 받아 컴포넌트 인스턴스에 접근할 수 있게 해줘요.

<Drawer.Content>{(instance) => <div>{instance.drawer?.state.open ? 'Open' : 'Closed'}</div>}</Drawer.Content>

패스 스루 (Pass Through)

<DocPTViewer name="drawer-pt" components={['DrawerRoot']} />

API

DrawerRoot

Attribute Value
data-open Present when the drawer is open
data-closed Present when the drawer is closed
data-position "left" | "right" | "top" | "bottom" | "full"
Label Type Description
root DrawerRootPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.
backdrop DrawerRootPassThroughType<HTMLAttributes> Used to pass attributes to the backdrop's DOM element.
trigger DrawerRootPassThroughType<HTMLAttributes> Used to pass attributes to the trigger's DOM element.
header DrawerRootPassThroughType<HTMLAttributes> Used to pass attributes to the header's DOM element.
title DrawerRootPassThroughType<HTMLAttributes> Used to pass attributes to the title's DOM element.
close DrawerRootPassThroughType<HTMLAttributes> Used to pass attributes to the close's DOM element.
content DrawerRootPassThroughType<HTMLAttributes> Used to pass attributes to the content's DOM element.
footer DrawerRootPassThroughType<HTMLAttributes> Used to pass attributes to the footer's DOM element.

DrawerTrigger

Label Type Description
root DrawerTriggerPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

DrawerPortal

Label Type Description
root DrawerPortalPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

DrawerBackdrop

Uses the Backdrop component internally for animated overlay rendering.

Label Type Description
root DrawerBackdropPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

DrawerPopup

Attribute Value
data-open Present when the drawer is open
data-position "left" | "right" | "top" | "bottom" | "full"

Uses VisuallyHidden elements internally for focus trap boundaries.

Label Type Description
root DrawerPopupPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

DrawerHeader

Label Type Description
root DrawerHeaderPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

DrawerTitle

Label Type Description
root DrawerTitlePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

DrawerClose

Label Type Description
root DrawerClosePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

DrawerContent

Label Type Description
root DrawerContentPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

DrawerFooter

Label Type Description
root DrawerFooterPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Drawer 컴포넌트는 기본적으로 complementary 역할을 사용해요. 속성이 루트 요소에 전달되므로 사용 사례에 따라 aria 역할을 바꿀 수 있고 aria-labelledby 같은 추가 속성도 붙일 수 있어요. 또한 열렸을 때 포커스가 드로어 안에 유지되므로 aria-modal이 추가돼요.

Trigger 요소에도 드로어 상태를 나타내는 aria-expanded와 aria-controls가 있어요.

오버레이 키보드 지원 (Overlay Keyboard Support)

Key Function
tab Moves focus to the next the focusable element within the drawer.
shift + tab Moves focus to the previous the focusable element within the drawer.
escape Closes the drawer.

닫기 버튼 키보드 지원 (Close Button Keyboard Support)

Key Function
enter Closes the drawer.
space Closes the drawer.

더 알아보기 (Learn more)