apps/www/content/docs/components/drawer.mdx
import { Drawer } from "@chakra-ui/react"
<Drawer.Root>
<Drawer.Backdrop />
<Drawer.Trigger />
<Drawer.Positioner>
<Drawer.Content>
<Drawer.CloseTrigger />
<Drawer.Header>
<Drawer.Title />
</Drawer.Header>
<Drawer.Body />
<Drawer.Footer />
</Drawer.Content>
</Drawer.Positioner>
</Drawer.Root>
Use the open and onOpenChange props to control the drawer component.
Use the size prop to change the size of the drawer component.
Use the DrawerContext component to access the drawer state and methods from
outside the drawer.
Use the padding CSS property on Drawer.Positioner to adjust the offset of
the drawer component.
Use the placement prop to change the placement of the drawer component.
Use the initialFocusEl prop to set the initial focus of the drawer component.
Here's an example of how to render the drawer component in a custom container.
Consider setting closeOnInteractOutside to false to prevent the drawer from
closing when interacting outside the drawer.
Here's an example of rendering actions in the header of the drawer component.
<ExampleTabs name="drawer-with-header-actions" />Here is an example of how to change variants based on the different breakpoints.
This example uses the mdDown breakpoint to change the drawer's placement on
smaller screens. This approach is recommended because both conditions are
translated into CSS media queries, which helps avoid base style merging issues.
If you really want to use the base condition instead, you’ll also need to define
corresponding sizes. For example:
<Drawer.Root placement={{ base: "bottom", md: "end" }} size={{ base: "xs", md: "md" }}>
We don't recommend using a non-modal drawer due to the accessibility concerns they present. In event you need it, here's what you can do:
modal prop to falsepointerEvents to none on the Drawer.Positioner componentcloseOnInteractOutside prop to false