--- title: Drawer description: "`Drawer` is a component for a panel that appears from the edge of the screen." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/drawer/drawer.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/drawer - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-drawer--basic --- # Drawer `Drawer` is a component for a panel that appears from the edge of the screen. ```tsx ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ``` ## Usage ```tsx import { Drawer } from "@yamada-ui/react" ``` ```tsx import { Drawer } from "@/components/ui" ``` ```tsx import { Drawer } from "@workspaces/ui" ``` ```tsx ``` :::note `Drawer.Overlay` and `Drawer.CloseButton` can be omitted. ::: :::tip To display a dialog in the center of the screen, use [Modal](https://yamada-ui.com/docs/components/modal.md). ::: ### Change Size ```tsx {(size) => ( ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 )} ``` ### Change Position To change the display position, set `placement` to values like `"block-start"` or `"inline-start"`. By default, `"inline-end"` is set. ```tsx {(placement) => ( ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 )} ``` ### Change Duration To change the duration, set `duration` to a numerical value (seconds). ```tsx ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ``` ### Do Not Block Scroll on Mount By default, scrolling of the main content is blocked when the panel is opened to ensure accessibility. If you do not want to block the scroll of the main content, set `blockScrollOnMount` to `false`. ```tsx ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ``` ### Disable the Close Button To disable the close button, set `withCloseButton` to `false`. ```tsx ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ``` ### Disable the Overlay To disable (hide) the overlay of the panel, set `withOverlay` to `false`. ```tsx ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ``` ### Close on drag If you want to close the `Drawer` on drag, set `closeOnDrag` to `true`. ```tsx ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ``` ### Hide the Drag Bar To hide the drag bar, set `withDragBar` to `false`. ```tsx ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ``` ### Customize the Close Button ```tsx ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ``` ### Customize the Overlay ```tsx ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ``` ### Control Use `open` and `onClose` to control the visibility. ```tsx const { open, onOpen, onClose } = useDisclosure() return ( <> ドラゴンボール 『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。 ) ``` ## Props ### Drawer.Root | Prop | Default | Type | Description | | ----------------------- | -------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `size` | `"lg"` | `"2xl" \| "3xl" \| "4xl" \| "5xl" \| "6xl" \| "full" \| "lg" \| "md" \| "sm" \| "xl" ...` | The size of the component. | | `allowPinchZoom` | `false.` | `boolean` | Handle zoom or pinch gestures on iOS devices when scroll locking is enabled. | | `blockScrollOnMount` | `true` | `boolean` | If `true`, scrolling will be disabled on the `body` when the drawer opens. | | `body` | - | `DrawerBodyProps \| ReactNode` | The drawer body to use. | | `cancel` | - | `ButtonProps \| ReactNode` | The drawer cancel button to use. | | `closeOnDrag` | `false` | `boolean` | If `true`, then the drawer will close on drag. | | `closeOnEsc` | `true` | `boolean` | If `true`, the modal will close when the `Esc` key is pressed. | | `closeOnOverlay` | `true` | `boolean` | If `true`, the modal will close when the overlay is clicked. | | `defaultOpen` | - | `boolean` | If `true`, the element will be initially opened. | | `dragConstraints` | `0` | `number` | Applies constraints on the permitted draggable area. | | `dragElastic` | `0.1` | `number` | The degree of movement allowed outside constraints. 0 = no movement, 1 = full movement. | | `dragHandleOnly` | `false` | `boolean` | If `true`, only the drag bar and drag triggers can start dragging when `closeOnDrag` is `true`. | | `dragOffset` | `80` | `number` | Offset from being dragged to closing. | | `dragVelocity` | `100` | `number` | Velocity of the drag that triggers close. | | `duration` | - | `MotionTransitionProps["duration"]` | The animation duration. | | `finalFocusRef` | - | `RefObject` | `ref` of the element to return focus to when `FocusLock` unmounts. | | `footer` | - | `DrawerFooterProps \| ReactNode` | The drawer footer to use. | | `header` | - | `DrawerHeaderProps \| ReactNode` | The drawer header to use. | | `initialFocusRef` | - | `RefObject` | `ref` of the element to receive focus initially. | | `lockFocusAcrossFrames` | `false` | `boolean` | Enables aggressive focus capturing within iframes. - If `true`: keep focus in the lock, no matter where lock is active. - If `false`: allows focus to move outside of iframe. | | `middle` | - | `ButtonProps \| ReactNode` | The drawer middle button to use. | | `onCancel` | - | `(onClose: () => void) => void` | The callback invoked when cancel button clicked. | | `onClose` | - | `() => void \| Promise` | Callback invoked to close the element. | | `onCloseComplete` | - | `() => void` | Callback function to run side effects after the drawer has closed. | | `onEsc` | - | `() => void` | Callback invoked when the escape key is pressed and focus is within modal. | | `onMiddle` | - | `(onClose: () => void) => void` | The callback invoked when middle button clicked. | | `onOpen` | - | `() => void \| Promise` | Callback invoked to open the element. | | `onSuccess` | - | `(onClose: () => void) => void` | The callback invoked when success button clicked. | | `open` | - | `boolean` | If `true`, the element will be opened. | | `portalProps` | - | `Omit` | Props to be forwarded to the portal component. | | `restoreFocus` | `false` | `boolean` | If `true`, focus will be restored to the element that triggered the `FocusLock` once it unmounts. | | `success` | - | `ButtonProps \| ReactNode` | The drawer success button to use. | | `title` | - | `DrawerTitleProps \| ReactNode` | The drawer title to use. | | `trigger` | - | `ReactNode` | The modal trigger to use. | | `withCloseButton` | `true` | `boolean` | If `true`, display the drawer close button. | | `withDragBar` | `true` | `boolean` | If `true`, display the drag bar when `closeOnDrag` is `true`. | | `withOverlay` | `true` | `boolean` | If `true`, display the drawer overlay. | ### Drawer.CloseButton | Prop | Default | Type | Description | | --------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | - | `"2xl" \| "2xs" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | - | `"ghost" \| "outline" \| "solid" \| "subtle" \| "surface" ...` | The variant of the component. | | `active` | `false` | `boolean` | If `true`, the button is represented as active. | | `disabled` | `false` | `boolean` | If `true`, the button is disabled. | | `disableRipple` | `false` | `boolean` | If `true`, disable ripple effects when pressing a element. | | `icon` | - | `string \| number \| bigint \| boolean \| ReactElement> \| Iterable \| ReactPortal \| Promise<...>` | The icon to be used in the button. | | `loading` | `false` | `boolean` | If `true`, the loading state of the button is represented. | | `type` | `"button"` | `"button" \| "reset" \| "submit"` | The type of button. Accepts `button`, `reset`, or `submit`. | ### Drawer.CloseTrigger | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Drawer.Content | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `keyof IntrinsicElements` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Drawer.DragBar | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Drawer.DragTrigger | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Drawer.Footer | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Drawer.Header | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Drawer.OpenTrigger | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Drawer.Overlay | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `DOMElement` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ### Drawer.Title | Prop | Default | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | ## Accessibility The `Drawer` follows the [WAI-ARIA - Dialog (Modal) Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/) for accessibility. If you use only an icon for `Drawer.OpenTrigger` or `Drawer.CloseTrigger`, set `aria-label` on the child element. ```tsx } /> } /> ``` ### Keyboard Navigation When the `Drawer` opens, focus is trapped within it. That is, you cannot focus on elements outside the modal unless the modal is closed. | Key | Description | State | | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | | `Tab` | Focuses the next element inside the modal that is not disabled. If it's the last element, focuses the first element that is not disabled. | `open={true}` | | `Shift` + `Tab` | Focuses the previous element inside the modal that is not disabled. If it's the first element, focuses the last element that is not disabled. | `open={true}` | | `Escape` | Closes the modal. | `open={true}` + `closeOnEsc={true}` | ### ARIA Roles and Attributes | Element | Roles and Attributes | Usage | | -------------------------------- | ------------------------ | ------------------------------------------------------------------------------------ | | `section.ui-drawer__content` | `role="dialog"` | Indicates that it is a dialog. | | | `aria-modal="true"` | Indicates that the displayed widget is modal. | | | `aria-labelledby` | Sets the `id` of the associated `Drawer.Title`. | | | `aria-describedby` | Sets the `id` of the associated `Drawer.Body`. | | `.ui-drawer__trigger--open` | `aria-expanded` | Sets to `"true"` when modal is opened, and `"false"` when it is closed. | | | `aria-controls` | Sets the `id` of `section.ui-drawer__content` when open, and is not set when closed. | | | `aria-haspopup="dialog"` | Indicates that a dialog exists. | | `button.ui-drawer__close-button` | `aria-label` | Sets to `"Close"`. | | `div.ui-drawer__overlay` | `aria-hidden` | Excludes the element from the accessibility tree. | ## Similar Components - [Modal](https://yamada-ui.com/docs/components/modal.md): `Modal` is a component that is displayed over the main content to focus the user's attention solely on the information. - [Popover](https://yamada-ui.com/docs/components/popover.md): `Popover` is a component that floats around an element to display information. - [Tooltip](https://yamada-ui.com/docs/components/tooltip.md): `Tooltip` is a component that displays short information, such as supplementary details for an element. - [Collapse](https://yamada-ui.com/docs/components/collapse.md): `Collapse` is a component that allows you to expand or collapse an element for display. - [Fade](https://yamada-ui.com/docs/components/fade.md): `Fade` is a component that gradually shows or hides an element. - [FadeScale](https://yamada-ui.com/docs/components/fade-scale.md): `FadeScale` is a component that gradually scales up to reveal or scales down to hide an element. - [NativePopover](https://yamada-ui.com/docs/components/native-popover.md): `NativePopover` is a component that floats around an element to display information using the HTML Popover API. - [Slide](https://yamada-ui.com/docs/components/slide.md): `Slide` is a component that shows or hides an element from the corners of the page. ## Uses Components & Hooks - [Modal](https://yamada-ui.com/docs/components/modal.md): `Modal` is a component that is displayed over the main content to focus the user's attention solely on the information. - [Button](https://yamada-ui.com/docs/components/button.md): `Button` is an interactive component that allows users to perform actions such as submitting forms and toggling modals. - [CloseButton](https://yamada-ui.com/docs/components/close-button.md): `CloseButton` is a component used primarily to trigger the close functionality of a component. - [FocusLock](https://yamada-ui.com/docs/components/focus-lock.md): `FocusLock` is a component that improves accessibility by restricting focus within elements such as modals and dialogs, and locking the focus within that range. - [Motion](https://yamada-ui.com/docs/components/motion.md): `Motion` is a convenient component that extends the Yamada UI Style Props to `Motion`. - [Portal](https://yamada-ui.com/docs/components/portal.md): `Portal` is a component that renders elements outside of the current `DOM` hierarchy. - [Slide](https://yamada-ui.com/docs/components/slide.md): `Slide` is a component that shows or hides an element from the corners of the page. - [Fade](https://yamada-ui.com/docs/components/fade.md): `Fade` is a component that gradually shows or hides an element. - [useValue](https://yamada-ui.com/docs/hooks/use-value.md): `useValue` is a custom hook that combines `useBreakpointValue` and `useColorModeValue`.