Loading...
Skip to main content

Drawer

Build hidden sidebars or drawers into your project for navigation, shopping carts, and more with React props and the native dialog API. Replaces the old Offcanvas component.

How it works

Drawer builds on the native <dialog> element and our Dialog component to manage hidden sidebars via JavaScript. These sidebars, or drawers, can appear from the left, right, top, or bottom edge of the viewport. Buttons or anchors are used as triggers that are attached to specific elements you toggle, and React state controls the open prop.

  • Drawer shares the same base as our Dialog component, using native <dialog> APIs for focus trapping, backdrop, and top-layer rendering.
  • Use the <dialog> element, not a <div>. The wrapper renders this element. Due to how CSS handles animations, don’t apply margin or translate directly to Drawer — wrap it if you need those.
  • Modal by default — opens with showModal(), a backdrop, and focus trapping. Set scroll: true and backdrop: false to open as a non-modal drawer with show(): body scrolling stays on, and focus is not trapped.
  • Built-in backdrop via ::backdrop (modal only) closes the drawer on click; set backdrop: "static" to lock clicks outside, or backdrop: false to hide it.
  • Escape key handling closes the drawer by default; set keyboard: false to disable.
  • Dismissal — the close button, Escape, and backdrop click close the drawer. The React wrapper does not currently implement the upstream swipe-to-dismiss gesture.
  • Responsive placement — responsive="sm", responsive="md", and up stay drawer-like below their breakpoint and collapse inline above it, making drawers useful as responsive navbars.
  • Coordinate open drawers through application state if only one should be shown at a time; the React wrapper does not use Bootstrap’s data API.
  • Animated open and close — drawer slides back out to its placement-specific off-screen position on close, with the ::backdrop fading alongside it when opened modally. When authoring custom CSS, qualify your [open] rules with :not(.hiding) so the exit transition can fall through to the base state; pass animation="instant" to skip animations.

The animation effect of this component is dependent on the prefers-reduced-motion media query.

Examples

Drawer components

Below is a drawer example that is shown by default (via open and modal={false}). Drawer includes support for a header with a close button and an optional body class for some initial padding. We suggest that you include drawer headers with dismiss actions whenever possible, or provide an explicit dismiss action.

Drawer

Content for the drawer goes here. You can place just about any Bootstrap component or custom elements here.

<Drawer
backdrop={false}
className="position-static"
modal={false}
open
placement="start"
scroll
title="Drawer"
>
<p>
Content for the drawer goes here. You can place just about any Bootstrap component or
custom elements here.
</p>
</Drawer>

Live demo

Use the buttons below to show and hide a drawer element via React state. Both a link and a button can invoke the same action, updating open. Use onDismiss to synchronize state after the close button, backdrop, or Escape is used.

Link with href
Drawer

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

Without JavaScript

Supported browsers can open and close a drawer with the Invoker Commands API—no Bootstrap JavaScript required. Set commandFor to the drawer’s id, use command="show-modal" to open, and command="close" to dismiss.

The Invoker Commands API is not supported in all browsers. For guaranteed support, use React-controlled open and onDismiss, as in the examples above, when you need wrapper options, callbacks, or animated close.

Invoker Commands

This drawer opens with command="show-modal".

<>
<Button
command="show-modal"
commandfor="invokerDrawer"
theme="primary"
variant="solid"
>
Open drawer
</Button>
<Drawer
id="invokerDrawer"
placement="start"
title="Invoker Commands"
>
<p>
This drawer opens with{' '}
<code>
command="show-modal"
</code>
.
</p>
<Button
command="close"
commandfor="invokerDrawer"
theme="secondary"
variant="solid"
>
Close drawer
</Button>
</Drawer>
</>

Body scrolling

Scrolling the <body> element is disabled when a drawer opens modally. Pass scroll with backdrop={false} to keep body scrolling and open the drawer as non-modal. Focus moves into the drawer, but is not trapped, so the page stays interactive.

Body scrolling

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
backdrop={false}
label="Enable body scrolling"
placement="start"
scroll
title="Body scrolling"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>

Body scrolling & backdrop

You can also allow <body> scrolling while keeping a backdrop. With a backdrop present, the drawer stays modal (showModal() and focus trapping) even when scroll is true.

Backdrop with scrolling

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
label="Enable both scrolling & backdrop"
placement="start"
scroll
title="Backdrop with scrolling"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>

Static backdrop

When backdrop is set to static, the drawer will not close when clicking outside of it.

Static backdrop

I will not close if you click outside of me.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
backdrop="static"
label="Toggle static drawer"
placement="start"
title="Static backdrop"
>
<p>
I will not close if you click outside of me.
</p>
</DrawerDemo>

Instant drawer

By default, drawers animate with a slide on open and close. To disable animations, pass animation="instant" to Drawer.

Instant drawer

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
animation="instant"
label="Toggle instant drawer"
placement="start"
title="Instant drawer"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>

Dark drawer

Change the appearance of drawers with utilities to better match them to different contexts like dark navbars. Here we pass theme="dark" to Drawer, and it makes all nested elements within use dark mode.

Dark drawer

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
label="Toggle dark drawer"
placement="start"
theme="dark"
title="Dark drawer"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>

Translucent drawer

Pass translucent to the drawer panel to blur and saturate the background. This makes the panel semi-transparent so content behind it shows through.

Translucent drawer

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
label="Toggle translucent drawer"
placement="start"
title="Translucent drawer"
translucent
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>

Sheet

Pass sheet to render the panel flush against the viewport edge. The sheet variant removes the drawer’s inset, border, border-radius, and box-shadow, so it sits edge-to-edge like a traditional offcanvas. It works with any placement.

Drawer sheet

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
label="Toggle sheet"
placement="bottom"
sheet
title="Drawer sheet"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>

Responsive

Responsive drawers hide content outside the viewport from a specified breakpoint and down. Above that breakpoint, the contents within will behave as usual. For example, responsive="lg" hides content in a drawer below the lg breakpoint, but shows the content above the lg breakpoint. Responsive drawers are available for each breakpoint.

To make a responsive drawer, set the responsive breakpoint prop. The wrapper wires its close button without an explicit target.

Responsive drawer

This drawer becomes inline content above the lg breakpoint. Resize the browser to see the change.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
label="Toggle responsive drawer"
placement="end"
responsive="lg"
title="Responsive drawer"
>
<p>
This drawer becomes inline content above the lg breakpoint. Resize the browser to see the
change.
</p>
</DrawerDemo>

Placement

Choose a placement for the drawer. Idea React defaults to "end".

  • placement="start" places drawer on the left of the viewport (shown above)
  • placement="end" places drawer on the right of the viewport
  • placement="top" places drawer on the top of the viewport
  • placement="bottom" places drawer on the bottom of the viewport
  • fullscreen covers the entire viewport

Try the top, right, bottom, and fullscreen examples out below.

Drawer

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
label="Toggle top drawer"
placement="top"
title="Drawer"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>
Drawer

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
label="Toggle end drawer"
placement="end"
title="Drawer"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>
Drawer

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
label="Toggle bottom drawer"
placement="bottom"
title="Drawer"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>
Fullscreen drawer

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
fullscreen
label="Toggle fullscreen drawer"
title="Fullscreen drawer"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>

Footer

Pass optional footer content for action buttons or other content at the bottom of the drawer.

Drawer with footer

Some text as placeholder. In real life you can have the elements you have chosen. Like text, images, lists, etc.

document/component/Document/DrawerDemo.tsx
<DrawerDemo
footer
label="Toggle drawer with footer"
placement="end"
title="Drawer with footer"
>
<p>
Some text as placeholder. In real life you can have the elements you have chosen. Like text,
images, lists, etc.
</p>
</DrawerDemo>

Accessibility

Since the drawer is a native <dialog>, it gets the correct dialog role. Modal drawers also get modal semantics and focus trapping from showModal(). Non-modal drawers (scroll: true and backdrop: false) use show() instead, so they do not trap focus or mark the rest of the page as inert. The wrapper supplies aria-label for a string title. When supplying custom title markup, provide an accessible aria-label or aria-labelledby.

CSS

Variables

Local CSS custom properties expose the component’s colors, spacing, borders, and transitions. Override them through style or a CSS module. The defaults below come from the Bootstrap stylesheet used by Idea React; see the upstream variable reference.

VariableDefault

Usage

Control open with React state and keep it synchronized through onDismiss. Native dialog behavior is supplied by Dialog.

Options

PropDefaultDescription
placement"end"Position the panel at start, end, top, or bottom.
backdroptrueClose on an outside click; "static" prevents outside dismissal, and false hides the backdrop.
keyboardtrueClose when Escape is pressed.
scrollfalseAllow body scrolling; combine with backdrop={false} for a non-modal drawer.
animation"slide"Choose the sliding transition or "instant".
responsive—Display inline above the selected breakpoint.

Events

onDismiss() runs when the drawer is dismissed by its close button, Escape, or a backdrop click. Use it to update the controlled open value.

Documentation navigation
On this page
On this page