Drawer
<wa-drawer>
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.
Examples
Drawer without Header
Headers are enabled by default. To render a drawer without a header, add the without-header attribute.
Drawer with Footer
Footers can be used to display titles and more. Use the footer slot to add a footer to the drawer.
Opening and Closing Drawers Declaratively
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.
Similarly, you can add data-drawer="close" to a button inside of a drawer to tell it to close.
Slide in From Start
By default, drawers slide in from the end. To make the drawer slide in from the start, set the placement attribute to start.
Slide in From Top
To make the drawer slide in from the top, set the placement attribute to top.
Slide in From Bottom
To make the drawer slide in from the bottom, set the placement attribute to bottom.
Custom Size
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.
Scrolling
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! 👇
Header Actions
The header shows a functional close button by default. You can use the header-actions slot to add additional buttons if needed.
Light Dismissal
If you want the drawer to close when the user clicks on the overlay, add the light-dismiss attribute.
Preventing the Drawer from Closing
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.
Setting Initial Focus
To give focus to a specific element when the drawer opens, use the autofocus attribute.
Importing
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.
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
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The drawer's main content. |
footer
|
The drawer's footer, usually one or more buttons representing various options. |
header-actions
|
Optional actions to add to the header. Works best with <wa-button>. |
label
|
The drawer's label. Alternatively, you can use the label attribute. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
css |
One or more CSSResultGroup to include in the component's shadow root. Host styles are automatically prepended.
Type
CSSResultGroup | undefinedDefault
styles |
||
labellabel |
The drawer's label as displayed in the header. You should always include a relevant label, as it is required for
proper accessibility. If you need to display HTML, use the
label slot instead.Type
stringDefault
'' |
|
|
lightDismisslight-dismiss |
When enabled, the drawer will be closed when the user clicks outside of it.
Type
booleanDefault
true |
||
modal |
Exposes the internal modal utility that controls focus trapping. To temporarily disable focus trapping and allow third-party modals spawned from an active Shoelace modal, call
modal.activateExternal() when the third-party modal opens. Upon closing, call modal.deactivateExternal() to restore Shoelace's focus trapping. |
||
openopen |
Indicates whether or not the drawer is open. Toggle this attribute to show and hide the drawer.
Type
booleanDefault
false |
|
|
placementplacement |
The direction from which the drawer will open.
Type
'top' | 'end' | 'bottom' | 'start'Default
'end' |
|
|
withFooterwith-footer |
Only required for SSR. Set to
true if you're slotting in a footer element so the server-rendered markup
includes the footer before the component hydrates on the client.Type
booleanDefault
false |
||
withoutHeaderwithout-header |
Disables the header. This will also remove the default close button.
Type
booleanDefault
false |
|
Events
Learn more about events.
| Name | Description |
|---|---|
wa-after-hide |
Emitted after the drawer closes and all animations are complete. |
wa-after-show |
Emitted after the drawer opens and all animations are complete. |
wa-hide |
Emitted when the drawer is requesting to close. Calling event.preventDefault() will prevent the drawer from closing. You can inspect event.detail.source to see which element caused the drawer to close. If the source is the drawer element itself, the user has pressed Escape or the drawer has been closed programmatically. Avoid using this unless closing the drawer will result in destructive behavior such as data loss. |
wa-show |
Emitted when the drawer opens. |
CSS custom properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--backdrop-filter |
A filter to apply to the backdrop behind the drawer.
Default
none
|
--hide-duration |
The animation duration when hiding the drawer.
Default
var(--wa-transition-normal)
|
--show-duration |
The animation duration when showing the drawer.
Default
var(--wa-transition-normal)
|
--size |
The preferred size of the drawer. This will be applied to the drawer's width or height depending on its
placement. Note that the drawer will shrink to accommodate smaller screens. |
--spacing |
The amount of space around and between the drawer's content.
|
CSS parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
body |
The drawer's body. |
::part(body)
|
close-button |
The close button, a <wa-button>. |
::part(close-button)
|
close-button__base |
The close button's exported base part. |
::part(close-button__base)
|
dialog |
The drawer's internal <dialog> element. |
::part(dialog)
|
footer |
The drawer's footer. |
::part(footer)
|
header |
The drawer's header. This element wraps the title and header actions. |
::part(header)
|
header-actions |
Optional actions to add to the header. Works best with <wa-button>. |
::part(header-actions)
|
title |
The drawer's title. |
::part(title)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.