Todae

Todae

Drawer

시작이나 끝 가장자리에 고정된, 높이를 가득 채우는 모달 네이티브 <dialog>입니다. Drawer.Root는 role을 뺀 Dialog.Root와 같은 props에 side를 더해 받고, 안쪽은 Drawer의 자체 파트로 만듭니다: Drawer.Header, Drawer.Title, Drawer.Description, Drawer.Body, Drawer.Footer, Drawer.Close.

이 페이지의 내용

Drawer.Header는 자식을 한 줄로 놓습니다. 헤더 바로 안에 둔 Drawer.Close는 그 뒤의 요소와 함께 끝에 놓이고, 그 앞의 제목 같은 내용은 시작 쪽에 머뭅니다. Drawer.Body는 헤더와 푸터가 남긴 높이를 채우고 스스로 스크롤하므로, 헤더는 위에, 푸터는 아래에 머뭅니다.

side의 기본값은 end입니다. 시작과 끝은 텍스트 방향을 따르므로, 오른쪽에서 왼쪽으로 쓰는 텍스트에서는 end가 왼쪽 가장자리입니다.

import { Button, Drawer, type DrawerSide } from '@tounsoo/todae';
import { useState } from 'react';

function FiltersDrawer({ side }: { side: DrawerSide }) {
  const [open, setOpen] = useState(false);
  return (
    <>
      <Button.Root variant="secondary" onClick={() => setOpen(true)}>
        {side === 'start' ? 'Open at start' : 'Open at end'}
      </Button.Root>
      <Drawer.Root open={open} onOpenChange={setOpen} side={side}>
        <Drawer.Header>
          <Drawer.Title>Filters</Drawer.Title>
          <Drawer.Close />
        </Drawer.Header>
        <Drawer.Body>The body fills the height the header and footer leave, and scrolls on its own.</Drawer.Body>
        <Drawer.Footer>
          <Button.Root variant="secondary" onClick={() => setOpen(false)}>
            Reset
          </Button.Root>
          <Button.Root onClick={() => setOpen(false)}>Apply</Button.Root>
        </Drawer.Footer>
      </Drawer.Root>
    </>
  );
}

export default function DrawerSides() {
  return (
    <>
      <FiltersDrawer side="end" />
      <FiltersDrawer side="start" />
    </>
  );
}

Filters

The body fills the height the header and footer leave, and scrolls on its own.

Filters

The body fills the height the header and footer leave, and scrolls on its own.

접근성을 지키는 조합

Todae가 맡는 것: Drawer.Root는 Dialog.Root와 같은 모달 코드로 동작하므로 Dialog의 내용이 모두 그대로 적용됩니다. 뒤의 페이지를 inert로 만드는 네이티브 모달 <dialog>, Drawer.Title과 Drawer.Description에서 오는 aria-labelledby와 aria-describedby, 열릴 때의 포커스, Escape와 배경 클릭으로 닫기, 닫힘 동작이 끝난 뒤 restoreFocusRef나 여는 요소로 돌아가는 포커스입니다. side는 패널의 위치만 정하고, 스크린 리더가 읽는 것은 더하지 않습니다.

직접 제공할 것: Drawer.Title이나 aria-label로 붙이는 이름, 그리고 닫는 Drawer.Close나 다른 버튼입니다. 개발 환경에서는 이름 없이 열린 드로어가 오류를 기록합니다. 드로어는 더 긴 작업을 담으므로, 각 구역에 제목의 h2보다 아래 단계의 제목을 붙이세요. 닫힐 때 여는 요소가 사라지고 없다면 restoreFocusRef를 넘기세요.

주의할 점: 평범한 제목으로 드로어 제목을 만드는 래퍼는 드로어에 이름을 남기지 않습니다. Drawer.Title을 감싸거나 aria-labelledby를 넘기세요. 드로어가 열린 동안 뒤의 페이지는 inert이므로, 옆에서 필터가 바로 갱신하는 목록은 드로어가 닫힐 때까지 읽을 수 없습니다. 중요하다면 결과 개수를 useAnnouncer로 알리세요.

언제 쓰나요

언제: 공간이 필요한 작업을 위한 모달 사이드 패널. 필터, 설정, 목록 옆의 상세 정보 같은 것. 이름은 Drawer.Title이나 aria-label로 붙이세요.

쓰지 않을 때: 짧은 가운데 작업이나 확인 → Dialog. 아래에서 올라오는 모바일 선택기 → BottomSheet. 페이지를 계속 쓸 수 있게 두는 패널 → 모달이 아닌 제품 레이아웃.

Props

Drawer.Root props
이름타입설명
openboolean

제어 열림 상태. 비제어 드로어에서는 생략하세요.

defaultOpenboolean

비제어일 때 마운트 시 드로어를 엽니다. 트리거 파트가 없어서 한 번 닫히면 다시 마운트해야 다시 열립니다.

기본값: false

onOpenChange(open: boolean, reason: DialogCloseReason) => void

닫기 요청. 이유는 Dialog.Root와 같습니다.

side'start' | 'end'

고정되는 인라인 가장자리. 텍스트 방향을 따릅니다.

기본값: 'end'

dismissOnEscapeboolean

Escape가 onOpenChange(false, "escape")를 호출합니다.

기본값: true

dismissOnBackdropboolean

스크림 클릭이 onOpenChange(false, "backdrop")을 호출합니다.

기본값: true

aria-labelstring

Drawer.Title을 생략했을 때의 이름.

Drawer.Title props
이름타입설명
childrenReact.ReactNode

제목 텍스트.

Drawer.Description props
이름타입설명
childrenReact.ReactNode

설명 텍스트.

Drawer.Close props
이름타입설명
aria-labelstring

접근 가능한 이름. "Cancel"처럼 글자나 숫자가 두 개 이상인 텍스트가 있으면 그 텍스트가 버튼의 이름이 됩니다. 그렇지 않으면 StringsProvider의 close 문자열이 이름이 되며, 영어로는 Close입니다.

기본값: "Close" when its text, not counting aria-hidden or SVG parts, has fewer than two letters or digits

onClickReact.MouseEventHandler<HTMLButtonElement>

닫기 요청 전에 실행됩니다. 드로어를 열어 두려면 event.preventDefault()를 호출하세요.