Web Awesome (ViUR)

Font Awesome
Try SSR Server-side rendering (SSR) generates component HTML on the server before the page loads, improving SEO and initial load time. Use the switch to see Web Awesome components render with and without SSR.
Search this website ⌘KCtrl+K Light Dark System Docs Select Color Scheme Default Awesome Shoelace Active Brutalist Glossy Matter Mellow Playful Premium Tailspin Docs Select Theme View Project on GitHub Star Project on GitHub
Start Components Docs Help
Web Awesome Font Awesome Build Awesome
Search this site… /
Try SSR Server-side rendering (SSR) generates component HTML on the server before the page loads, improving SEO and initial load time. Use the switch to see Web Awesome components render with and without SSR.
Light Dark System Docs Select Color Scheme Default Awesome Shoelace Active Brutalist Glossy Matter Mellow Playful Premium Tailspin Docs Select Theme

Getting Started

  • Installation
  • Usage
  • Forms
  • Localization
  • Frameworks
  • Using with AI
  • Figma Design Kit ProThis requires access to Web Awesome Pro
  • Server Rendering

Resources

  • Accessibility
  • Browser Support
  • Contributing
  • Patterns ProPatterns require access to Web Awesome Pro
  • Migrating from Shoelace
  • Visual Tests
  • Changelog
  • Help & Support

Theming & Utilities

  • Overview
  • Built-in Themes
  • Color Palettes
  • Design Tokens
  • Customizing & Theming
  • CSS Utilities

ViUR Components

  • Alert
  • Combobox
  • Pagination
  • Table Wrapper

Actions

  • Button
  • Button Group
  • Copy Button
  • Dropdown
    • Dropdown Item

Forms

  • Checkbox
  • Checkbox Group
  • Color Picker
  • Input
  • Known Date
  • Number Input
  • Radio Group
    • Radio
  • Rating
  • Select
    • Option
  • Slider
  • Switch
  • Textarea
  • Time Input
  • Data Grid Planned A Web Awesome Kickstarter stretch goal!

Layout

  • Accordion
    • Accordion Item
  • Card
  • Details
  • Dialog
  • Divider
  • Drawer
  • Page
  • Scroller
  • Split Panel

Navigation

  • Breadcrumb
    • Breadcrumb Item
  • Tab Group
    • Tab
    • Tab Panel
  • Tree
    • Tree Item

Feedback

  • Badge
  • Callout
  • Progress Bar
  • Progress Ring
  • Skeleton
  • Spinner
  • Tag
  • Tooltip

Media

  • Animated Image
  • Avatar
  • Carousel
    • Carousel Item
  • Comparison
  • Icon
  • Markdown
  • QR Code
  • Zoomable Frame

Data Viz

  • Advanced Usage

Helpers

  • Animation
  • Format Bytes
  • Format Date
  • Format Number
  • Include
  • Intersection Observer
  • Mutation Observer
  • Popover
  • Popup
  • Random Content
  • Relative Time
  • Resize Observer

Drawer

  • Examples
  • Drawer Without Header
  • Drawer with Footer
  • Opening & Closing Drawers Declaratively
  • Slide in from Start
  • Slide in from Top
  • Slide in from Bottom
  • Custom Size
  • Scrolling
  • Header Actions
  • Light Dismissal
  • Preventing the Drawer from Closing
  • Setting Initial Focus
  • Importing
  • Slots
  • Attributes & Properties
  • Events
  • CSS Custom Properties
  • CSS Parts
  • Dependencies
On This Page...
  • Examples
  • Drawer Without Header
  • Drawer with Footer
  • Opening & Closing Drawers Declaratively
  • Slide in from Start
  • Slide in from Top
  • Slide in from Bottom
  • Custom Size
  • Scrolling
  • Header Actions
  • Light Dismissal
  • Preventing the Drawer from Closing
  • Setting Initial Focus
  • Importing
  • Slots
  • Attributes & Properties
  • Events
  • CSS Custom Properties
  • CSS Parts
  • Dependencies

Drawer

<wa-drawer>
Stable Layout 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
<wa-drawer label="Drawer" id="drawer-overview">
  Drawers are great for showing additional content without leaving the current page.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('#drawer-overview');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

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
<wa-drawer label="Drawer" without-header class="drawer-without-header">
  Look ma, no header!
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-without-header');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

Drawer with Footer

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
<wa-drawer label="Drawer" class="drawer-footer">
  This drawer has a footer where you can put actions and other controls.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-footer');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

Opening & 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
<wa-drawer label="Drawer" id="drawer-opening">
  This drawer was opened declaratively using a data attribute on the button.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled" data-drawer="open drawer-opening">Open Drawer</wa-button>

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
<wa-drawer label="Drawer" id="drawer-dismiss">
  Click the button below to close this drawer — no JavaScript required!
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled" data-drawer="open drawer-dismiss">Open Drawer</wa-button>

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
<wa-drawer label="Drawer" placement="start" class="drawer-placement-start">
  This drawer slides in from the start.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-placement-start');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

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
<wa-drawer label="Drawer" placement="top" class="drawer-placement-top">
  This drawer slides in from the top.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-placement-top');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

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
<wa-drawer label="Drawer" placement="bottom" class="drawer-placement-bottom">
  This drawer slides in from the bottom.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-placement-bottom');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

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
<wa-drawer label="Drawer" class="drawer-custom-size" style="--size: 50vw;">
  This drawer is always 50% of the viewport.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-custom-size');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

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
<wa-drawer label="Drawer" class="drawer-scrolling">
  <div style="height: 150vh; border: dashed 2px var(--wa-color-surface-border); padding: 0 1rem;">
    <p>Scroll down and give it a try! 👇</p>
  </div>
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-scrolling');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

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
<wa-drawer label="Drawer" class="drawer-header-actions">
  <wa-button class="new-window" slot="header-actions" appearance="plain">
    <wa-icon name="arrow-up-right-from-square" variant="solid" label="Open in new window"></wa-icon>
  </wa-button>
  You can add custom actions to the header, like the button up there to open in a new window.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-header-actions');
  const openButton = drawer.nextElementSibling;
  const newWindowButton = drawer.querySelector('.new-window');

  openButton.addEventListener('click', () => (drawer.open = true));
  newWindowButton.addEventListener('click', () => window.open(location.href));
</script>

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
<wa-drawer label="Drawer" light-dismiss class="drawer-light-dismiss">
  This drawer will close when you click on the overlay.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-light-dismiss');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

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
<wa-drawer label="Drawer" class="drawer-deny-close">
  This drawer will only close when you click the button below.
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-deny-close');
  const openButton = drawer.nextElementSibling;
  const closeButton = drawer.querySelector('wa-button[slot="footer"]');

  openButton.addEventListener('click', () => (drawer.open = true));

  // Prevent the drawer from closing unless the close button is clicked
  drawer.addEventListener('wa-hide', event => {
    if (event.detail.source !== closeButton) {
      event.preventDefault();
    }
  });
</script>

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
<wa-drawer label="Drawer" class="drawer-focus">
  <wa-input autofocus placeholder="I will have focus when the drawer is opened"></wa-input>
  <wa-button slot="footer" variant="brand" data-drawer="close">Close</wa-button>
</wa-drawer>

<wa-button appearance="filled">Open Drawer</wa-button>

<script>
  const drawer = document.querySelector('.drawer-focus');
  const input = drawer.querySelector('wa-input');
  const openButton = drawer.nextElementSibling;

  openButton.addEventListener('click', () => (drawer.open = true));
</script>

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/webawesome@0.17.0/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.

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

Link to This Section

Learn more about attributes and properties.

Name Description Reflects
label
label
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 string
Default ''
lightDismiss
light-dismiss
When enabled, the drawer will be closed when the user clicks outside of it.
Type boolean
Default false
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.
open
open
Indicates whether or not the drawer is open. Toggle this attribute to show and hide the drawer.
Type boolean
Default false
placement
placement
The direction from which the drawer will open.
Type 'top' | 'end' | 'bottom' | 'start'
Default 'end'
withFooter
with-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 boolean
Default false
withoutHeader
without-header
Disables the header. This will also remove the default close button.
Type boolean
Default false

Events

Link to This Section

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

Link to This Section

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

Link to This Section

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

Link to This Section

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

  • <wa-button>
  • <wa-icon>
  • <wa-spinner>
Need a hand? Report a bug Ask for help
Go Make Something Awesome
Version 0.17.0 © Fonticons, Inc.
  • Terms
  • Privacy
  • Refunds
  • Core License
  • Pro License

Quick Links

  • Components
  • CSS Utilities
  • Theming
  • Using with AI
  • Changelog
  • Help & Support

Recent Searches

    D'oh! No results for “”

    Suggest on GitHub Ask on Discord
    Navigate Select
    Close Esc