Drawers
<button type="button" class="btn" data-variant="outline" data-dialog-open="demo-drawer">Filters</button>
<dialog id="demo-drawer" class="drawer" data-side="right" aria-labelledby="demo-drawer-title">
<article>
<header class="flex-row items-center justify-between">
<h2 id="demo-drawer-title">Filters</h2>
<button type="button" class="btn" data-variant="ghost" data-size="icon-sm" aria-label="Close" data-dialog-close><i class="icon icon-x" aria-hidden="true"></i></button>
</header>
<section class="px-4">
<form id="demo-drawer-form" class="flex flex-col gap-4" onsubmit="event.preventDefault(); this.closest('dialog').close()">
<div role="group" class="field">
<label for="demo-drawer-is-public">Is Public</label>
<select class="select w-full" id="demo-drawer-is-public" name="is_public">
<option value="unknown">-------</option>
<option value="true">Yes</option>
<option value="false">No</option>
</select>
</div>
<div role="group" class="field">
<label for="demo-drawer-is-gift-card">Is Gift Card</label>
<select class="select w-full" id="demo-drawer-is-gift-card" name="is_gift_card">
<option value="unknown">-------</option>
<option value="true">Yes</option>
<option value="false">No</option>
</select>
</div>
</form>
</section>
<footer>
<button type="submit" form="demo-drawer-form" class="btn w-full">Search</button>
</footer>
</article>
</dialog>
data-side="left" slides in from the left edge
<button type="button" class="btn" data-variant="outline" data-dialog-open="demo-drawer-left">Menu</button>
<dialog id="demo-drawer-left" class="drawer" data-side="left" aria-labelledby="demo-drawer-left-title">
<article>
<header class="flex-row items-center justify-between">
<h2 id="demo-drawer-left-title">Menu</h2>
<button type="button" class="btn" data-variant="ghost" data-size="icon-sm" aria-label="Close" data-dialog-close><i class="icon icon-x" aria-hidden="true"></i></button>
</header>
<section class="px-2">
<nav class="flex flex-col" aria-label="Store">
<a href="#" class="btn justify-start" data-variant="ghost"><i class="icon icon-house" aria-hidden="true"></i>Home</a>
<a href="#" class="btn justify-start" data-variant="ghost"><i class="icon icon-package" aria-hidden="true"></i>Products</a>
<a href="#" class="btn justify-start" data-variant="ghost"><i class="icon icon-shopping-bag" aria-hidden="true"></i>Orders</a>
<a href="#" class="btn justify-start" data-variant="ghost"><i class="icon icon-user" aria-hidden="true"></i>Customers</a>
</nav>
</section>
</article>
</dialog>
data-side="bottom", or no data-side, slides up from the bottom edge
<button type="button" class="btn" data-variant="outline" data-dialog-open="demo-drawer-bottom">Delete Products</button>
<dialog id="demo-drawer-bottom" class="drawer" data-side="bottom" aria-labelledby="demo-drawer-bottom-title">
<article>
<header class="mx-auto w-full max-w-sm">
<h2 id="demo-drawer-bottom-title">Delete 3 products?</h2>
<p>They are removed from every category and campaign. This cannot be undone.</p>
</header>
<footer class="mx-auto w-full max-w-sm">
<button type="button" class="btn" data-variant="destructive" data-dialog-close>Delete Products</button>
<button type="button" class="btn" data-variant="outline" data-dialog-close>Cancel</button>
</footer>
</article>
</dialog>
data-side="top" slides down from the top edge
<button type="button" class="btn" data-variant="outline" data-dialog-open="demo-drawer-top">Announcement</button>
<dialog id="demo-drawer-top" class="drawer" data-side="top" aria-labelledby="demo-drawer-top-title">
<article>
<header class="mx-auto w-full max-w-sm">
<h2 id="demo-drawer-top-title">Scheduled maintenance</h2>
<p>Payments are paused on Sunday from 2:00 to 2:30 a.m. Orders placed then are captured afterwards.</p>
</header>
<footer class="mx-auto w-full max-w-sm">
<button type="button" class="btn" data-dialog-close>Got it</button>
</footer>
</article>
</dialog>
close() takes a value, and the page reads it from the close event
Nothing chosen yet.
<div class="flex flex-col items-start gap-3">
<button type="button" class="btn" data-variant="outline" data-dialog-open="demo-drawer-value">Export Orders</button>
<p class="text-muted-foreground text-sm" id="demo-drawer-value-result">Nothing chosen yet.</p>
</div>
<dialog id="demo-drawer-value" class="drawer" data-side="bottom" aria-labelledby="demo-drawer-value-title">
<article>
<header class="mx-auto w-full max-w-sm">
<h2 id="demo-drawer-value-title">Export orders</h2>
<p>Choose the file format.</p>
</header>
<footer class="mx-auto w-full max-w-sm">
<button type="button" class="btn" onclick="this.closest('dialog').close('csv')">CSV</button>
<button type="button" class="btn" data-variant="outline" onclick="this.closest('dialog').close('xlsx')">Excel</button>
</footer>
</article>
</dialog>
<script>
document.addEventListener("DOMContentLoaded", () => {
const drawer = document.getElementById("demo-drawer-value");
drawer.addEventListener("close", () => {
document.getElementById("demo-drawer-value-result").textContent = drawer.returnValue === "" ? "Closed without a choice." : "Chosen: " + drawer.returnValue;
});
});
</script>
API Reference
Attributes
| Attribute | On | Values | Default | Description |
|---|---|---|---|---|
| data-side | dialog.drawer | "bottom", "top", "left", "right" | "bottom" | The edge the drawer slides in from. |
| data-closing | dialog.drawer | "true" | set by the script | Present while the drawer slides out. Do not write it. |
Methods and properties
| Member | Type | Description |
|---|---|---|
| showModal() | method | The dialog's own method. Opens the drawer over a dimmed page. |
| close(returnValue) | method | Closes the drawer after its slide-out has run. With reduced motion, or no transition, it closes at once. |
Events
| Event | On | Detail | Description |
|---|---|---|---|
| close | dialog.drawer | none | The dialog's own event, sent once the drawer has closed. Read dialog.returnValue for the value given to close(). |
Keyboard
| Key | Description |
|---|---|
| Escape | Closes the drawer, with its slide-out. |
A click that starts and ends on the dimmed area closes the drawer. A drag that ends there does not.
Once the script has started it, the element carries data-drawer-initialized="true" and sends tsugi:initialized. The methods and properties above are on the element itself.