Drawer

Drawer

A drawer is a side sheet built on native <dialog>, opened with Invoker Commands. Focus trapping, Esc to close and the inert background come from the platform.

Class names

Class nameTypeDescription
drawerComponentPut on a `<dialog>`; slides in from the inline-start edge
drawer-endModifierSlide in from the inline-end edge instead
commandfor / commandStateOn a button: `command="show-modal"` opens, `command="close"` closes
closedby="any"StateDialog attribute: closes on backdrop click as well as Esc

Drawer

Give the dialog an aria-label. Both edges flip automatically in right-to-left languages.

<button class="btn" commandfor="drawer-ex1" command="show-modal">Open drawer</button>
<dialog id="drawer-ex1" class="drawer" aria-label="Navigation" closedby="any">
  <button class="btn btn-ghost btn-sm" commandfor="drawer-ex1" command="close">Close</button>
  <ul class="menu">
    <li class="menu-title">Navigate</li>
    <li><a href="#" aria-current="page">Home</a></li>
    <li><a href="#">Projects</a></li>
    <li><a href="#">Settings</a></li>
  </ul>
</dialog>

End edge

Filters go here.

<button class="btn" commandfor="drawer-ex2" command="show-modal">Open from the end</button>
<dialog id="drawer-ex2" class="drawer drawer-end" aria-label="Filters" closedby="any">
  <button class="btn btn-ghost btn-sm" commandfor="drawer-ex2" command="close">Close</button>
  <p>Filters go here.</p>
</dialog>

With a labelled heading

Point aria-labelledby at a visible heading instead of using aria-label.

Your cart

Your cart is empty.

<button class="btn btn-primary" commandfor="drawer-ex3" command="show-modal">Cart</button>
<dialog id="drawer-ex3" class="drawer drawer-end" aria-labelledby="drawer-ex3-title" closedby="any">
  <h2 id="drawer-ex3-title">Your cart</h2>
  <p>Your cart is empty.</p>
  <button class="btn btn-ghost" commandfor="drawer-ex3" command="close">Continue shopping</button>
</dialog>

Esc only

Drop closedby="any" so the backdrop does not close the drawer; Esc and the close button still do.

Edit profile

<button class="btn" commandfor="drawer-ex4" command="show-modal">Edit profile</button>
<dialog id="drawer-ex4" class="drawer" aria-labelledby="drawer-ex4-title">
  <h2 id="drawer-ex4-title">Edit profile</h2>
  <label for="drawer-ex4-name">Name</label>
  <input id="drawer-ex4-name" class="input" type="text" value="Ada Lovelace">
  <div style="display: flex; gap: 0.5rem; margin-block-start: 1rem">
    <button class="btn btn-primary" commandfor="drawer-ex4" command="close">Save</button>
    <button class="btn btn-ghost" commandfor="drawer-ex4" command="close">Cancel</button>
  </div>
</dialog>