Drawer
Drawer is a component for a panel that appears from the edge of the screen.
<Drawer.Root>
<Drawer.OpenTrigger>
<Button>Open Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
Usage
import { Drawer } from "@yamada-ui/react"
import { Drawer } from "@/components/ui"
import { Drawer } from "@workspaces/ui"
<Drawer.Root>
<Drawer.OpenTrigger />
<Drawer.Content>
<Drawer.Overlay />
<Drawer.CloseButton />
<Drawer.Header />
<Drawer.Body />
<Drawer.Footer />
<Drawer.CloseTrigger />
</Drawer.Content>
</Drawer.Root>
Drawer.Overlay and Drawer.CloseButton can be omitted.Change Size
<Wrap gap="md">
<For each={["xs", "sm", "md", "lg", "xl", "full"]}>
{(size) => (
<Drawer.Root key={size} size={size}>
<Drawer.OpenTrigger>
<Button>Open "{size}" Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
)}
</For>
</Wrap>
Change Position
To change the display position, set placement to values like "block-start" or "inline-start". By default, "inline-end" is set.
<Wrap gap="md">
<For each={["block-start", "inline-start", "inline-end", "block-end"]}>
{(placement) => (
<Drawer.Root key={placement} placement={placement}>
<Drawer.OpenTrigger>
<Button>Open "{placement}" Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
)}
</For>
</Wrap>
Change Duration
To change the duration, set duration to a numerical value (seconds).
<Drawer.Root duration={0.7}>
<Drawer.OpenTrigger>
<Button>Open Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
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.
<Drawer.Root blockScrollOnMount={false}>
<Drawer.OpenTrigger>
<Button>Open Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
Disable the Close Button
To disable the close button, set withCloseButton to false.
<Drawer.Root withCloseButton={false}>
<Drawer.OpenTrigger>
<Button>Open Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
Disable the Overlay
To disable (hide) the overlay of the panel, set withOverlay to false.
<Drawer.Root withOverlay={false}>
<Drawer.OpenTrigger>
<Button>Open Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
Close on drag
If you want to close the Drawer on drag, set closeOnDrag to true.
<Drawer.Root closeOnDrag>
<Drawer.OpenTrigger>
<Button>Open Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
Hide the Drag Bar
To hide the drag bar, set withDragBar to false.
<Drawer.Root closeOnDrag withDragBar={false}>
<Drawer.OpenTrigger>
<Button>Open Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
Customize the Close Button
<Drawer.Root>
<Drawer.OpenTrigger>
<Button>Open Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Content>
<Drawer.CloseButton colorScheme="red" />
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
Customize the Overlay
<Drawer.Root>
<Drawer.OpenTrigger>
<Button>Open Drawer</Button>
</Drawer.OpenTrigger>
<Drawer.Overlay bg="blackAlpha.300" backdropFilter="blur(10px)" />
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Drawer.CloseTrigger>
<Button variant="ghost">とじる</Button>
</Drawer.CloseTrigger>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
Control
Use open and onClose to control the visibility.
const { open, onOpen, onClose } = useDisclosure()
return (
<>
<Button onClick={onOpen}>Open Drawer</Button>
<Drawer.Root open={open} onClose={onClose}>
<Drawer.Content>
<Drawer.Header>ドラゴンボール</Drawer.Header>
<Drawer.Body>
『ドラゴンボール』は、鳥山明による日本の漫画作品です。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</Drawer.Body>
<Drawer.Footer>
<Button variant="ghost" onClick={onClose}>
とじる
</Button>
<Button>Wikipedia</Button>
</Drawer.Footer>
</Drawer.Content>
</Drawer.Root>
</>
)
"use client" to the top of the file.Props
Accessibility
The Drawer follows the WAI-ARIA - Dialog (Modal) Pattern for accessibility.
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
| Component | Roles and Attributes | Usage |
|---|---|---|
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. | |
Drawer.OpenTrigger | aria-expanded | Sets to "true" when modal is opened, and "false" when it is closed. |
aria-controls | Sets the id of the Drawer.Content when open, and is not set when closed. | |
aria-haspopup="dialog" | Indicates that a dialog exists. | |
aria-label | Sets to "Open modal". | |
Drawer.CloseButton | aria-label | Sets to "Close modal". |
Drawer.CloseTrigger | aria-label | Sets to "Close modal". |
Drawer.Overlay | aria-hidden="true" | Excludes the element from the accessibility tree. |
Similar Components
Modal
Modal is a component that is displayed over the main content to focus the user's attention solely on the information.
Popover
Popover is a component that floats around an element to display information.
Tooltip
Tooltip is a component that displays short information, such as supplementary details for an element.
Collapse
Collapse is a component that allows you to expand or collapse an element for display.
Fade
Fade is a component that gradually shows or hides an element.
FadeScale
FadeScale is a component that gradually scales up to reveal or scales down to hide an element.
NativePopover
NativePopover is a component that floats around an element to display information using the HTML Popover API.
Slide
Slide is a component that shows or hides an element from the corners of the page.
Uses Components & Hooks
Modal
Modal is a component that is displayed over the main content to focus the user's attention solely on the information.
Button
Button is an interactive component that allows users to perform actions such as submitting forms and toggling modals.
CloseButton
CloseButton is a component used primarily to trigger the close functionality of a component.
FocusLock
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
Motion is a convenient component that extends the Yamada UI Style Props to Motion.
Portal
Portal is a component that renders elements outside of the current DOM hierarchy.
Slide
Slide is a component that shows or hides an element from the corners of the page.
Fade
Fade is a component that gradually shows or hides an element.