Drawer

<wa-drawer> Stable Since 2.0

Drawers slide in from the edge of a container to expose additional options and information without navigating away. Useful for navigation menus, filters, and secondary content.

Drawers are great for showing additional content without leaving the current page. Close Open Drawer

Examples

Link to This Section

Drawer without Header

Link to This Section

Headers are enabled by default. To render a drawer without a header, add the without-header attribute.

Look ma, no header! Close Open Drawer
Link to This Section

Footers can be used to display titles and more. Use the footer slot to add a footer to the drawer.

This drawer has a footer where you can put actions and other controls. Close Open Drawer

Opening and Closing Drawers Declaratively

Link to This Section

You can open and close drawers with JavaScript by toggling the open attribute, but you can also do it declaratively. Add the data-drawer="open id" to any button on the page, where id is the ID of the drawer you want to open.

This drawer was opened declaratively using a data attribute on the button. Close Open Drawer

Similarly, you can add data-drawer="close" to a button inside of a drawer to tell it to close.

Click the button below to close this drawer — no JavaScript required! Close Open Drawer

Slide in From Start

Link to This Section

By default, drawers slide in from the end. To make the drawer slide in from the start, set the placement attribute to start.

This drawer slides in from the start. Close Open Drawer

Slide in From Top

Link to This Section

To make the drawer slide in from the top, set the placement attribute to top.

This drawer slides in from the top. Close Open Drawer

Slide in From Bottom

Link to This Section

To make the drawer slide in from the bottom, set the placement attribute to bottom.

This drawer slides in from the bottom. Close Open Drawer

Custom Size

Link to This Section

Use the --size custom property to set the drawer's size. This will be applied to the drawer's width or height depending on its placement.

This drawer is always 50% of the viewport. Close Open Drawer

Scrolling

Link to This Section

By design, a drawer's height will never exceed 100% of its container. As such, drawers will not scroll with the page to ensure the header and footer are always accessible to the user.

Scroll down and give it a try! 👇

Close
Open Drawer

Header Actions

Link to This Section

The header shows a functional close button by default. You can use the header-actions slot to add additional buttons if needed.

You can add custom actions to the header, like the button up there to open in a new window. Close Open Drawer

Light Dismissal

Link to This Section

If you want the drawer to close when the user clicks on the overlay, add the light-dismiss attribute.

This drawer will close when you click on the overlay. Close Open Drawer

Preventing the Drawer from Closing

Link to This Section

By default, drawers will close when the user clicks the close button, clicks the overlay, or presses the Escape key. In most cases, the default behavior is the best behavior in terms of UX. However, there are situations where this may be undesirable, such as when data loss will occur.

To keep the drawer open in such cases, you can cancel the wa-hide event. When canceled, the drawer will remain open and pulse briefly to draw the user's attention to it.

You can use event.detail.source to determine what triggered the request to close. This example prevents the drawer from closing when the overlay is clicked, but allows the close button or Escape to dismiss it.

This drawer will only close when you click the button below. Close Open Drawer

Setting Initial Focus

Link to This Section

To give focus to a specific element when the drawer opens, use the autofocus attribute.

Close Open Drawer

Importing

Link to This Section

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/[email protected]/components/drawer/drawer.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/drawer/drawer.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/drawer/drawer.js';

To import this component for React 18 or below, use the following code:

import WaDrawer from '@awesome.me/webawesome/dist/react/drawer/index.js';

Slots

Link to This Section

Learn more about using slots.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Events

Link to This Section

Learn more about events.

CSS custom properties

Link to This Section

Learn more about CSS custom properties.

CSS parts

Link to This Section

Learn more about CSS parts.

Dependencies

Link to This Section

This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.

Need a hand? Report a bug Ask for help
    No results