Skip to content
@samline/drawerv6.0.1
OverviewGet startedRecipesFAQExamplesDocs

@samline/drawer

Explore Drawer

A starting point, a working example, and the details when you need them.

  • 01OverviewUnderstand the problem and the approach.
  • 02Get startedChoose your setup and follow the first steps.
  • 03RecipesUseful patterns and integration context.
  • 04FAQFind the practical details.
  • 05ExamplesTry a preview and explore its code.
  • 06DocsRead guides and the complete reference.

Around the project

  • GitHub(opens in a new tab)
  • npm(opens in a new tab)

v6.0.1·MIT

GitHub(opens in a new tab)Get started
Examples

Drawer examples.

Try eighteen Drawer examples: filters, nested flows, snap points, non-modal inspectors and more. Copy runnable HTML/CDN or ESM files.

Try the exampleInstallation guide

Modal examples manage focus and restore it on close. The non-modal inspector leaves the page interactive. Each example includes named actions; the draft confirmation requires an explicit choice.

Choose an example

The everyday bottom sheetA command panel from aboveNavigation with room to browseA side panel for the detailsThree stops. One fluid sheet.Open a drawer inside anotherFilters that return a resultRead more without losing your placeKeep the page interactiveDrag the handle, not the contentUpdate content in placeChoose the size explicitlyAn account menu that travels with youA file action sheet, ready for touchMake consequential choices explicitA guided flow, one step at a timeTwo panels, independent livesThe same Drawer, a different design
01 / bottom

The everyday bottom sheet

The everyday bottom sheetLive · @samline/drawer

YOUR BAG · 2 ITEMS

Good things, ready to go.

A little more room for the next step. Drag down, press Escape, or use the close button.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">YOUR BAG · 2 ITEMS</p>
          <h3>Good things, ready to go.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote</strong>
                <p>Natural canvas · Qty 1</p>
              </div>
              <span>$32</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Studio notebook</strong>
                <p>Dotted pages · Qty 1</p>
              </div>
              <span>$18</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Subtotal</strong>
                <p>Delivery is chosen at checkout.</p>
              </div>
              <span>$50</span>
            </div>
          </div>
          <button type="button" data-demo-choice="Review checkout" data-drawer-no-drag>
            Review checkout
          </button>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Your shopping bag',
  description: 'Review the items, quantities and subtotal before continuing.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">YOUR BAG · 2 ITEMS</p>
          <h3>Good things, ready to go.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote</strong>
                <p>Natural canvas · Qty 1</p>
              </div>
              <span>$32</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Studio notebook</strong>
                <p>Dotted pages · Qty 1</p>
              </div>
              <span>$18</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Subtotal</strong>
                <p>Delivery is chosen at checkout.</p>
              </div>
              <span>$50</span>
            </div>
          </div>
          <button type="button" data-demo-choice="Review checkout" data-drawer-no-drag>
            Review checkout
          </button>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Your shopping bag',
        description: 'Review the items, quantities and subtotal before continuing.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">YOUR BAG · 2 ITEMS</p>
          <h3>Good things, ready to go.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote</strong>
                <p>Natural canvas · Qty 1</p>
              </div>
              <span>$32</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Studio notebook</strong>
                <p>Dotted pages · Qty 1</p>
              </div>
              <span>$18</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Subtotal</strong>
                <p>Delivery is chosen at checkout.</p>
              </div>
              <span>$50</span>
            </div>
          </div>
          <button type="button" data-demo-choice="Review checkout" data-drawer-no-drag>
            Review checkout
          </button>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Your shopping bag',
  description: 'Review the items, quantities and subtotal before continuing.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">YOUR BAG · 2 ITEMS</p>
          <h3>Good things, ready to go.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote</strong>
                <p>Natural canvas · Qty 1</p>
              </div>
              <span>$32</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Studio notebook</strong>
                <p>Dotted pages · Qty 1</p>
              </div>
              <span>$18</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Subtotal</strong>
                <p>Delivery is chosen at checkout.</p>
              </div>
              <span>$50</span>
            </div>
          </div>
          <button type="button" data-demo-choice="Review checkout" data-drawer-no-drag>
            Review checkout
          </button>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Your shopping bag',
        description: 'Review the items, quantities and subtotal before continuing.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
02 / top

A command panel from above

A command panel from aboveLive · @samline/drawer

QUICK COMMANDS

What would you like to do?

Keep quick actions within reach, then dismiss the panel to return to your page.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">QUICK COMMANDS</p>
          <h3>What would you like to do?</h3>
          <label
            >Search commands<input
              type="search"
              data-demo-search
              placeholder="Try project, document or teammate…"
              data-drawer-no-drag
          /></label>

          <div
            class="demo-menu"
            role="group"
            aria-label="What would you like to do?"
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Create a project">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M12 5v14M5 12h14" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Create a project</strong><span>Start with a clean canvas</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Find a document">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="11" cy="11" r="6.5" />
                  <path d="m20 20-4.2-4.2" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Find a document</strong><span>Search your workspace</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Invite a teammate">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="9" cy="8" r="4" />
                  <path d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M19 8v6M16 11h6" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Invite a teammate</strong><span>Make room for collaboration</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p data-demo-empty hidden role="status">No commands match. Try another name.</p>
          <p class="demo-hint">Find a command by typing a project, document or teammate action.</p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  left: 0;
  right: 0;
  border-radius: 0 0 1.5rem 1.5rem;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'top',
  title: 'Quick actions',
  description: 'Search for a workspace command and choose your next action.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )
    body.querySelector('[data-demo-search]').addEventListener(
      'input',
      event => {
        const query = event.currentTarget.value.trim().toLocaleLowerCase()
        choices.forEach(button => {
          button.hidden = !button.textContent.toLocaleLowerCase().includes(query)
        })
        body.querySelector('[data-demo-empty]').hidden = choices.some(button => !button.hidden)
      },
      { signal: lifecycle.signal }
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        left: 0;
        right: 0;
        border-radius: 0 0 1.5rem 1.5rem;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">QUICK COMMANDS</p>
          <h3>What would you like to do?</h3>
          <label
            >Search commands<input
              type="search"
              data-demo-search
              placeholder="Try project, document or teammate…"
              data-drawer-no-drag
          /></label>

          <div
            class="demo-menu"
            role="group"
            aria-label="What would you like to do?"
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Create a project">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M12 5v14M5 12h14" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Create a project</strong><span>Start with a clean canvas</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Find a document">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="11" cy="11" r="6.5" />
                  <path d="m20 20-4.2-4.2" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Find a document</strong><span>Search your workspace</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Invite a teammate">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="9" cy="8" r="4" />
                  <path d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M19 8v6M16 11h6" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Invite a teammate</strong><span>Make room for collaboration</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p data-demo-empty hidden role="status">No commands match. Try another name.</p>
          <p class="demo-hint">Find a command by typing a project, document or teammate action.</p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'top',
        title: 'Quick actions',
        description: 'Search for a workspace command and choose your next action.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )
          body.querySelector('[data-demo-search]').addEventListener(
            'input',
            event => {
              const query = event.currentTarget.value.trim().toLocaleLowerCase()
              choices.forEach(button => {
                button.hidden = !button.textContent.toLocaleLowerCase().includes(query)
              })
              body.querySelector('[data-demo-empty]').hidden = choices.some(
                button => !button.hidden
              )
            },
            { signal: lifecycle.signal }
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">QUICK COMMANDS</p>
          <h3>What would you like to do?</h3>
          <label
            >Search commands<input
              type="search"
              data-demo-search
              placeholder="Try project, document or teammate…"
              data-drawer-no-drag
          /></label>

          <div
            class="demo-menu"
            role="group"
            aria-label="What would you like to do?"
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Create a project">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M12 5v14M5 12h14" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Create a project</strong><span>Start with a clean canvas</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Find a document">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="11" cy="11" r="6.5" />
                  <path d="m20 20-4.2-4.2" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Find a document</strong><span>Search your workspace</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Invite a teammate">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="9" cy="8" r="4" />
                  <path d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M19 8v6M16 11h6" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Invite a teammate</strong><span>Make room for collaboration</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p data-demo-empty hidden role="status">No commands match. Try another name.</p>
          <p class="demo-hint">Find a command by typing a project, document or teammate action.</p>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  left: 0;
  right: 0;
  border-radius: 0 0 1.5rem 1.5rem;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'top',
  title: 'Quick actions',
  description: 'Search for a workspace command and choose your next action.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )
    body.querySelector('[data-demo-search]').addEventListener(
      'input',
      event => {
        const query = event.currentTarget.value.trim().toLocaleLowerCase()
        choices.forEach(button => {
          button.hidden = !button.textContent.toLocaleLowerCase().includes(query)
        })
        body.querySelector('[data-demo-empty]').hidden = choices.some(button => !button.hidden)
      },
      { signal: lifecycle.signal }
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        left: 0;
        right: 0;
        border-radius: 0 0 1.5rem 1.5rem;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">QUICK COMMANDS</p>
          <h3>What would you like to do?</h3>
          <label
            >Search commands<input
              type="search"
              data-demo-search
              placeholder="Try project, document or teammate…"
              data-drawer-no-drag
          /></label>

          <div
            class="demo-menu"
            role="group"
            aria-label="What would you like to do?"
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Create a project">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M12 5v14M5 12h14" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Create a project</strong><span>Start with a clean canvas</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Find a document">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="11" cy="11" r="6.5" />
                  <path d="m20 20-4.2-4.2" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Find a document</strong><span>Search your workspace</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Invite a teammate">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="9" cy="8" r="4" />
                  <path d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M19 8v6M16 11h6" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Invite a teammate</strong><span>Make room for collaboration</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p data-demo-empty hidden role="status">No commands match. Try another name.</p>
          <p class="demo-hint">Find a command by typing a project, document or teammate action.</p>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'top',
        title: 'Quick actions',
        description: 'Search for a workspace command and choose your next action.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )
          body.querySelector('[data-demo-search]').addEventListener(
            'input',
            event => {
              const query = event.currentTarget.value.trim().toLocaleLowerCase()
              choices.forEach(button => {
                button.hidden = !button.textContent.toLocaleLowerCase().includes(query)
              })
              body.querySelector('[data-demo-empty]').hidden = choices.some(
                button => !button.hidden
              )
            },
            { signal: lifecycle.signal }
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
03 / left

Navigation with room to browse

Navigation with room to browseLive · @samline/drawer

STUDIO / WORKSPACE

A place for your next idea.

Open navigation from the left edge without leaving the current page.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">STUDIO / WORKSPACE</p>
          <h3>A place for your next idea.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="A place for your next idea."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Overview">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="3" y="3" width="18" height="18" rx="2" />
                  <path d="M3 9h18M9 21V9" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Overview</strong><span>Your projects at a glance</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Projects">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Projects</strong><span>12 active projects</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Team">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="9" cy="8" r="4" />
                  <path
                    d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M16 3.5a4 4 0 0 1 0 8M22 21v-1a6 6 0 0 0-4-5.6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Team</strong><span>People and permissions</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Settings">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Settings</strong><span>Make this space yours</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Browse projects, invite your team or change workspace settings.</p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'left',
  title: 'Studio workspace',
  description: 'Choose a project, team or workspace settings destination.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">STUDIO / WORKSPACE</p>
          <h3>A place for your next idea.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="A place for your next idea."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Overview">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="3" y="3" width="18" height="18" rx="2" />
                  <path d="M3 9h18M9 21V9" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Overview</strong><span>Your projects at a glance</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Projects">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Projects</strong><span>12 active projects</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Team">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="9" cy="8" r="4" />
                  <path
                    d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M16 3.5a4 4 0 0 1 0 8M22 21v-1a6 6 0 0 0-4-5.6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Team</strong><span>People and permissions</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Settings">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Settings</strong><span>Make this space yours</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Browse projects, invite your team or change workspace settings.</p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'left',
        title: 'Studio workspace',
        description: 'Choose a project, team or workspace settings destination.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">STUDIO / WORKSPACE</p>
          <h3>A place for your next idea.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="A place for your next idea."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Overview">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="3" y="3" width="18" height="18" rx="2" />
                  <path d="M3 9h18M9 21V9" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Overview</strong><span>Your projects at a glance</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Projects">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Projects</strong><span>12 active projects</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Team">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="9" cy="8" r="4" />
                  <path
                    d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M16 3.5a4 4 0 0 1 0 8M22 21v-1a6 6 0 0 0-4-5.6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Team</strong><span>People and permissions</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Settings">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Settings</strong><span>Make this space yours</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Browse projects, invite your team or change workspace settings.</p>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'left',
  title: 'Studio workspace',
  description: 'Choose a project, team or workspace settings destination.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">STUDIO / WORKSPACE</p>
          <h3>A place for your next idea.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="A place for your next idea."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Overview">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="3" y="3" width="18" height="18" rx="2" />
                  <path d="M3 9h18M9 21V9" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Overview</strong><span>Your projects at a glance</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Projects">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Projects</strong><span>12 active projects</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Team">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <circle cx="9" cy="8" r="4" />
                  <path
                    d="M2 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1M16 3.5a4 4 0 0 1 0 8M22 21v-1a6 6 0 0 0-4-5.6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Team</strong><span>People and permissions</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Settings">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Settings</strong><span>Make this space yours</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Browse projects, invite your team or change workspace settings.</p>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'left',
        title: 'Studio workspace',
        description: 'Choose a project, team or workspace settings destination.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
04 / right

A side panel for the details

A side panel for the detailsLive · @samline/drawer

THE EVERYDAY COLLECTION

Carry a little less.

Keep the page in view while you explore. The same API works from all four edges.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">THE EVERYDAY COLLECTION</p>
          <h3>Carry a little less.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote</strong>
                <p>A lightweight canvas bag for the daily essentials.</p>
              </div>
              <span>$32</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Materials and fit</strong>
                <p>Recycled cotton · 38 × 42 cm · In stock</p>
              </div>
              <span>14 L</span>
            </div>
          </div>
          <button type="button" data-demo-choice="Add to your shortlist" data-drawer-no-drag>
            Add to your shortlist
          </button>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'right',
  title: 'Everyday tote',
  description: 'Review materials, dimensions and price before shortlisting this item.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        right: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">THE EVERYDAY COLLECTION</p>
          <h3>Carry a little less.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote</strong>
                <p>A lightweight canvas bag for the daily essentials.</p>
              </div>
              <span>$32</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Materials and fit</strong>
                <p>Recycled cotton · 38 × 42 cm · In stock</p>
              </div>
              <span>14 L</span>
            </div>
          </div>
          <button type="button" data-demo-choice="Add to your shortlist" data-drawer-no-drag>
            Add to your shortlist
          </button>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'right',
        title: 'Everyday tote',
        description: 'Review materials, dimensions and price before shortlisting this item.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">THE EVERYDAY COLLECTION</p>
          <h3>Carry a little less.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote</strong>
                <p>A lightweight canvas bag for the daily essentials.</p>
              </div>
              <span>$32</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Materials and fit</strong>
                <p>Recycled cotton · 38 × 42 cm · In stock</p>
              </div>
              <span>14 L</span>
            </div>
          </div>
          <button type="button" data-demo-choice="Add to your shortlist" data-drawer-no-drag>
            Add to your shortlist
          </button>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'right',
  title: 'Everyday tote',
  description: 'Review materials, dimensions and price before shortlisting this item.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        right: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">THE EVERYDAY COLLECTION</p>
          <h3>Carry a little less.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote</strong>
                <p>A lightweight canvas bag for the daily essentials.</p>
              </div>
              <span>$32</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Materials and fit</strong>
                <p>Recycled cotton · 38 × 42 cm · In stock</p>
              </div>
              <span>14 L</span>
            </div>
          </div>
          <button type="button" data-demo-choice="Add to your shortlist" data-drawer-no-drag>
            Add to your shortlist
          </button>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'right',
        title: 'Everyday tote',
        description: 'Review materials, dimensions and price before shortlisting this item.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
05 / bottom

Three stops. One fluid sheet.

Three stops. One fluid sheet.Live · @samline/drawer

WEEKEND IN MEXICO CITY

A day with room to wander.

Drag the sheet or click its handle to move between ordered snap points.

Closed

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">WEEKEND IN MEXICO CITY</p>
          <h3>A day with room to wander.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Coffee in Roma Norte</strong>
                <p>Start slowly with a neighborhood walk.</p>
              </div>
              <span>09:00</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Explore Chapultepec</strong>
                <p>Art, a picnic and a little fresh air.</p>
              </div>
              <span>11:30</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Dinner with friends</strong>
                <p>Leave the evening open for something new.</p>
              </div>
              <span>19:00</span>
            </div>
          </div>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}
.demo-drawer {
  height: 100dvh;
  max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
  padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Your day in Mexico City',
  description: 'Browse the stops and times in this sample day itinerary.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  snapPoints: [0.45, 0.72, 1],
  activeSnapPoint: 0.45,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }
      .demo-drawer {
        height: 100dvh;
        max-height: 100dvh;
      }
      .demo-drawer[data-state='open'] {
        padding-bottom: calc(2rem + var(--initial-transform, 0rem));
      }
      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">WEEKEND IN MEXICO CITY</p>
          <h3>A day with room to wander.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Coffee in Roma Norte</strong>
                <p>Start slowly with a neighborhood walk.</p>
              </div>
              <span>09:00</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Explore Chapultepec</strong>
                <p>Art, a picnic and a little fresh air.</p>
              </div>
              <span>11:30</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Dinner with friends</strong>
                <p>Leave the evening open for something new.</p>
              </div>
              <span>19:00</span>
            </div>
          </div>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Your day in Mexico City',
        description: 'Browse the stops and times in this sample day itinerary.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        snapPoints: [0.45, 0.72, 1],
        activeSnapPoint: 0.45,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">WEEKEND IN MEXICO CITY</p>
          <h3>A day with room to wander.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Coffee in Roma Norte</strong>
                <p>Start slowly with a neighborhood walk.</p>
              </div>
              <span>09:00</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Explore Chapultepec</strong>
                <p>Art, a picnic and a little fresh air.</p>
              </div>
              <span>11:30</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Dinner with friends</strong>
                <p>Leave the evening open for something new.</p>
              </div>
              <span>19:00</span>
            </div>
          </div>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}
.demo-drawer {
  height: 100dvh;
  max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
  padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Your day in Mexico City',
  description: 'Browse the stops and times in this sample day itinerary.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  snapPoints: [0.45, 0.72, 1],
  activeSnapPoint: 0.45,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }
      .demo-drawer {
        height: 100dvh;
        max-height: 100dvh;
      }
      .demo-drawer[data-state='open'] {
        padding-bottom: calc(2rem + var(--initial-transform, 0rem));
      }
      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">WEEKEND IN MEXICO CITY</p>
          <h3>A day with room to wander.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Coffee in Roma Norte</strong>
                <p>Start slowly with a neighborhood walk.</p>
              </div>
              <span>09:00</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Explore Chapultepec</strong>
                <p>Art, a picnic and a little fresh air.</p>
              </div>
              <span>11:30</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Dinner with friends</strong>
                <p>Leave the evening open for something new.</p>
              </div>
              <span>19:00</span>
            </div>
          </div>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Your day in Mexico City',
        description: 'Browse the stops and times in this sample day itinerary.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        snapPoints: [0.45, 0.72, 1],
        activeSnapPoint: 0.45,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
06 / bottom

Open a drawer inside another

Open a drawer inside anotherLive · @samline/drawer

CHECKOUT / DELIVERY

Review your delivery.

Open a child drawer. Drawer coordinates its parent, focus, and shared scroll lock.

Closed

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">CHECKOUT / DELIVERY</p>
          <h3>Review your delivery.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote + Studio notebook</strong>
                <p>Two items · subtotal before delivery.</p>
              </div>
              <span>$50</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Delivery options</strong>
                <p>Choose a delivery option below.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M5 12h14M13 5l7 7-7 7" /></svg
              ></span>
            </div>
          </div>

          <p data-delivery-summary role="status">No delivery selected</p>
          <template data-delivery-content
            ><div class="demo-body">
              <div class="demo-menu" role="group" aria-label="Delivery options" data-drawer-no-drag>
                <button
                  type="button"
                  class="demo-menu-item"
                  data-demo-delivery="Standard delivery · $0 · 3–5 business days"
                >
                  <span class="demo-menu-icon" aria-hidden="true"
                    ><svg
                      aria-hidden="true"
                      focusable="false"
                      width="1.25rem"
                      height="1.25rem"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="1.75"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                    >
                      <path d="m21 8-9-5-9 5v8l9 5 9-5Z" />
                      <path d="m3 8 9 5 9-5M12 13v8" /></svg></span
                  ><span class="demo-menu-copy"
                    ><strong>Standard delivery</strong
                    ><span>Free · Arrives in 3–5 business days</span></span
                  ><svg
                    aria-hidden="true"
                    focusable="false"
                    width="1em"
                    height="1em"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="1.75"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                  >
                    <path d="M5 12h14M13 5l7 7-7 7" />
                  </svg></button
                ><button
                  type="button"
                  class="demo-menu-item"
                  data-demo-delivery="Express delivery · $8 · 1–2 business days"
                >
                  <span class="demo-menu-icon" aria-hidden="true"
                    ><svg
                      aria-hidden="true"
                      focusable="false"
                      width="1.25rem"
                      height="1.25rem"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="1.75"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                    >
                      <path d="M13 2 3 14h9l-1 8 10-12h-9Z" /></svg></span
                  ><span class="demo-menu-copy"
                    ><strong>Express delivery</strong
                    ><span>$8 · Arrives in 1–2 business days</span></span
                  ><svg
                    aria-hidden="true"
                    focusable="false"
                    width="1em"
                    height="1em"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="1.75"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                  >
                    <path d="M5 12h14M13 5l7 7-7 7" />
                  </svg>
                </button>
              </div></div></template
          ><button type="button" data-child data-drawer-no-drag>Choose delivery</button>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')
let child

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Order summary',
  description: 'Choose delivery while keeping your two items and subtotal in view.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)
    body.querySelector('[data-child]').addEventListener(
      'click',
      () => {
        const deliveryContent = () => {
          const choices = body
            .querySelector('[data-delivery-content]')
            .content.firstElementChild.cloneNode(true)
          choices.querySelectorAll('button[data-demo-delivery]').forEach(button =>
            button.addEventListener(
              'click',
              () => {
                body.querySelector('[data-delivery-summary]').textContent =
                  button.dataset.demoDelivery
                child.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )
          return choices
        }
        if (child) child.update({ content: deliveryContent })
        child ??= window.Drawer.createDrawer({
          id: 'example-child',
          parentId: 'example',
          title: 'Choose your delivery',
          description: 'Compare the cost and arrival time. Your order stays open underneath.',
          content: deliveryContent,
          autoFocus: true,
          contentClassName: 'demo-drawer',
          overlayClassName: 'demo-overlay',
          showHandle: true,
          closeButton: { ariaLabel: 'Close child' },
        })
        child.setOpen(true)
      },
      { signal: lifecycle.signal }
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">CHECKOUT / DELIVERY</p>
          <h3>Review your delivery.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote + Studio notebook</strong>
                <p>Two items · subtotal before delivery.</p>
              </div>
              <span>$50</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Delivery options</strong>
                <p>Choose a delivery option below.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M5 12h14M13 5l7 7-7 7" /></svg
              ></span>
            </div>
          </div>

          <p data-delivery-summary role="status">No delivery selected</p>
          <template data-delivery-content
            ><div class="demo-body">
              <div class="demo-menu" role="group" aria-label="Delivery options" data-drawer-no-drag>
                <button
                  type="button"
                  class="demo-menu-item"
                  data-demo-delivery="Standard delivery · $0 · 3–5 business days"
                >
                  <span class="demo-menu-icon" aria-hidden="true"
                    ><svg
                      aria-hidden="true"
                      focusable="false"
                      width="1.25rem"
                      height="1.25rem"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="1.75"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                    >
                      <path d="m21 8-9-5-9 5v8l9 5 9-5Z" />
                      <path d="m3 8 9 5 9-5M12 13v8" /></svg></span
                  ><span class="demo-menu-copy"
                    ><strong>Standard delivery</strong
                    ><span>Free · Arrives in 3–5 business days</span></span
                  ><svg
                    aria-hidden="true"
                    focusable="false"
                    width="1em"
                    height="1em"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="1.75"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                  >
                    <path d="M5 12h14M13 5l7 7-7 7" />
                  </svg></button
                ><button
                  type="button"
                  class="demo-menu-item"
                  data-demo-delivery="Express delivery · $8 · 1–2 business days"
                >
                  <span class="demo-menu-icon" aria-hidden="true"
                    ><svg
                      aria-hidden="true"
                      focusable="false"
                      width="1.25rem"
                      height="1.25rem"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="1.75"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                    >
                      <path d="M13 2 3 14h9l-1 8 10-12h-9Z" /></svg></span
                  ><span class="demo-menu-copy"
                    ><strong>Express delivery</strong
                    ><span>$8 · Arrives in 1–2 business days</span></span
                  ><svg
                    aria-hidden="true"
                    focusable="false"
                    width="1em"
                    height="1em"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="1.75"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                  >
                    <path d="M5 12h14M13 5l7 7-7 7" />
                  </svg>
                </button>
              </div></div></template
          ><button type="button" data-child data-drawer-no-drag>Choose delivery</button>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')
      let child

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Order summary',
        description: 'Choose delivery while keeping your two items and subtotal in view.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)
          body.querySelector('[data-child]').addEventListener(
            'click',
            () => {
              const deliveryContent = () => {
                const choices = body
                  .querySelector('[data-delivery-content]')
                  .content.firstElementChild.cloneNode(true)
                choices.querySelectorAll('button[data-demo-delivery]').forEach(button =>
                  button.addEventListener(
                    'click',
                    () => {
                      body.querySelector('[data-delivery-summary]').textContent =
                        button.dataset.demoDelivery
                      child.setOpen(false)
                    },
                    { signal: lifecycle.signal }
                  )
                )
                return choices
              }
              if (child) child.update({ content: deliveryContent })
              child ??= window.Drawer.createDrawer({
                id: 'example-child',
                parentId: 'example',
                title: 'Choose your delivery',
                description: 'Compare the cost and arrival time. Your order stays open underneath.',
                content: deliveryContent,
                autoFocus: true,
                contentClassName: 'demo-drawer',
                overlayClassName: 'demo-overlay',
                showHandle: true,
                closeButton: { ariaLabel: 'Close child' },
              })
              child.setOpen(true)
            },
            { signal: lifecycle.signal }
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">CHECKOUT / DELIVERY</p>
          <h3>Review your delivery.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote + Studio notebook</strong>
                <p>Two items · subtotal before delivery.</p>
              </div>
              <span>$50</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Delivery options</strong>
                <p>Choose a delivery option below.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M5 12h14M13 5l7 7-7 7" /></svg
              ></span>
            </div>
          </div>

          <p data-delivery-summary role="status">No delivery selected</p>
          <template data-delivery-content
            ><div class="demo-body">
              <div class="demo-menu" role="group" aria-label="Delivery options" data-drawer-no-drag>
                <button
                  type="button"
                  class="demo-menu-item"
                  data-demo-delivery="Standard delivery · $0 · 3–5 business days"
                >
                  <span class="demo-menu-icon" aria-hidden="true"
                    ><svg
                      aria-hidden="true"
                      focusable="false"
                      width="1.25rem"
                      height="1.25rem"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="1.75"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                    >
                      <path d="m21 8-9-5-9 5v8l9 5 9-5Z" />
                      <path d="m3 8 9 5 9-5M12 13v8" /></svg></span
                  ><span class="demo-menu-copy"
                    ><strong>Standard delivery</strong
                    ><span>Free · Arrives in 3–5 business days</span></span
                  ><svg
                    aria-hidden="true"
                    focusable="false"
                    width="1em"
                    height="1em"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="1.75"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                  >
                    <path d="M5 12h14M13 5l7 7-7 7" />
                  </svg></button
                ><button
                  type="button"
                  class="demo-menu-item"
                  data-demo-delivery="Express delivery · $8 · 1–2 business days"
                >
                  <span class="demo-menu-icon" aria-hidden="true"
                    ><svg
                      aria-hidden="true"
                      focusable="false"
                      width="1.25rem"
                      height="1.25rem"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="1.75"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                    >
                      <path d="M13 2 3 14h9l-1 8 10-12h-9Z" /></svg></span
                  ><span class="demo-menu-copy"
                    ><strong>Express delivery</strong
                    ><span>$8 · Arrives in 1–2 business days</span></span
                  ><svg
                    aria-hidden="true"
                    focusable="false"
                    width="1em"
                    height="1em"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="1.75"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                  >
                    <path d="M5 12h14M13 5l7 7-7 7" />
                  </svg>
                </button>
              </div></div></template
          ><button type="button" data-child data-drawer-no-drag>Choose delivery</button>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')
let child

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Order summary',
  description: 'Choose delivery while keeping your two items and subtotal in view.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)
    body.querySelector('[data-child]').addEventListener(
      'click',
      () => {
        const deliveryContent = () => {
          const choices = body
            .querySelector('[data-delivery-content]')
            .content.firstElementChild.cloneNode(true)
          choices.querySelectorAll('button[data-demo-delivery]').forEach(button =>
            button.addEventListener(
              'click',
              () => {
                body.querySelector('[data-delivery-summary]').textContent =
                  button.dataset.demoDelivery
                child.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )
          return choices
        }
        if (child) child.update({ content: deliveryContent })
        child ??= createDrawer({
          id: 'example-child',
          parentId: 'example',
          title: 'Choose your delivery',
          description: 'Compare the cost and arrival time. Your order stays open underneath.',
          content: deliveryContent,
          autoFocus: true,
          contentClassName: 'demo-drawer',
          overlayClassName: 'demo-overlay',
          showHandle: true,
          closeButton: { ariaLabel: 'Close child' },
        })
        child.setOpen(true)
      },
      { signal: lifecycle.signal }
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">CHECKOUT / DELIVERY</p>
          <h3>Review your delivery.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Everyday tote + Studio notebook</strong>
                <p>Two items · subtotal before delivery.</p>
              </div>
              <span>$50</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Delivery options</strong>
                <p>Choose a delivery option below.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M5 12h14M13 5l7 7-7 7" /></svg
              ></span>
            </div>
          </div>

          <p data-delivery-summary role="status">No delivery selected</p>
          <template data-delivery-content
            ><div class="demo-body">
              <div class="demo-menu" role="group" aria-label="Delivery options" data-drawer-no-drag>
                <button
                  type="button"
                  class="demo-menu-item"
                  data-demo-delivery="Standard delivery · $0 · 3–5 business days"
                >
                  <span class="demo-menu-icon" aria-hidden="true"
                    ><svg
                      aria-hidden="true"
                      focusable="false"
                      width="1.25rem"
                      height="1.25rem"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="1.75"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                    >
                      <path d="m21 8-9-5-9 5v8l9 5 9-5Z" />
                      <path d="m3 8 9 5 9-5M12 13v8" /></svg></span
                  ><span class="demo-menu-copy"
                    ><strong>Standard delivery</strong
                    ><span>Free · Arrives in 3–5 business days</span></span
                  ><svg
                    aria-hidden="true"
                    focusable="false"
                    width="1em"
                    height="1em"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="1.75"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                  >
                    <path d="M5 12h14M13 5l7 7-7 7" />
                  </svg></button
                ><button
                  type="button"
                  class="demo-menu-item"
                  data-demo-delivery="Express delivery · $8 · 1–2 business days"
                >
                  <span class="demo-menu-icon" aria-hidden="true"
                    ><svg
                      aria-hidden="true"
                      focusable="false"
                      width="1.25rem"
                      height="1.25rem"
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      stroke-width="1.75"
                      stroke-linecap="round"
                      stroke-linejoin="round"
                    >
                      <path d="M13 2 3 14h9l-1 8 10-12h-9Z" /></svg></span
                  ><span class="demo-menu-copy"
                    ><strong>Express delivery</strong
                    ><span>$8 · Arrives in 1–2 business days</span></span
                  ><svg
                    aria-hidden="true"
                    focusable="false"
                    width="1em"
                    height="1em"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="1.75"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                  >
                    <path d="M5 12h14M13 5l7 7-7 7" />
                  </svg>
                </button>
              </div></div></template
          ><button type="button" data-child data-drawer-no-drag>Choose delivery</button>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')
      let child

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Order summary',
        description: 'Choose delivery while keeping your two items and subtotal in view.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)
          body.querySelector('[data-child]').addEventListener(
            'click',
            () => {
              const deliveryContent = () => {
                const choices = body
                  .querySelector('[data-delivery-content]')
                  .content.firstElementChild.cloneNode(true)
                choices.querySelectorAll('button[data-demo-delivery]').forEach(button =>
                  button.addEventListener(
                    'click',
                    () => {
                      body.querySelector('[data-delivery-summary]').textContent =
                        button.dataset.demoDelivery
                      child.setOpen(false)
                    },
                    { signal: lifecycle.signal }
                  )
                )
                return choices
              }
              if (child) child.update({ content: deliveryContent })
              child ??= createDrawer({
                id: 'example-child',
                parentId: 'example',
                title: 'Choose your delivery',
                description: 'Compare the cost and arrival time. Your order stays open underneath.',
                content: deliveryContent,
                autoFocus: true,
                contentClassName: 'demo-drawer',
                overlayClassName: 'demo-overlay',
                showHandle: true,
                closeButton: { ariaLabel: 'Close child' },
              })
              child.setOpen(true)
            },
            { signal: lifecycle.signal }
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
07 / bottom

Filters that return a result

Filters that return a resultLive · @samline/drawer

Your page, uninterrupted

Keep the context.

Choose a category and apply it. A labeled form owns the input; Drawer owns focus and dismissal.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <form data-demo-form data-drawer-no-drag>
            <label for="category">Category</label
            ><select id="category" name="category">
              <option>All products</option>
              <option>Books</option>
              <option>Tools</option></select
            ><label
              >Sort by<select name="sort">
                <option>Recommended</option>
                <option>Newest first</option>
                <option>Price: low to high</option>
              </select></label
            >
            <p class="demo-hint">
              Narrow the collection, then return to browsing. Your selection is reported below the
              preview.
            </p>
            <button type="submit">Apply filters</button>
          </form>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Filter the collection',
  description: 'Choose a category and sort order for the collection.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    body.querySelector('form').addEventListener(
      'submit',
      event => {
        event.preventDefault()
        const values = new FormData(event.currentTarget)
        const category = values.get('category')
        const sort = values.get('sort')
        document.getElementById('demo-result').textContent =
          'Selected category:' + ' ' + category + ' · ' + sort
        drawer.setOpen(false)
      },
      { signal: lifecycle.signal }
    )
    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <form data-demo-form data-drawer-no-drag>
            <label for="category">Category</label
            ><select id="category" name="category">
              <option>All products</option>
              <option>Books</option>
              <option>Tools</option></select
            ><label
              >Sort by<select name="sort">
                <option>Recommended</option>
                <option>Newest first</option>
                <option>Price: low to high</option>
              </select></label
            >
            <p class="demo-hint">
              Narrow the collection, then return to browsing. Your selection is reported below the
              preview.
            </p>
            <button type="submit">Apply filters</button>
          </form>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Filter the collection',
        description: 'Choose a category and sort order for the collection.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          body.querySelector('form').addEventListener(
            'submit',
            event => {
              event.preventDefault()
              const values = new FormData(event.currentTarget)
              const category = values.get('category')
              const sort = values.get('sort')
              document.getElementById('demo-result').textContent =
                'Selected category:' + ' ' + category + ' · ' + sort
              drawer.setOpen(false)
            },
            { signal: lifecycle.signal }
          )
          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <form data-demo-form data-drawer-no-drag>
            <label for="category">Category</label
            ><select id="category" name="category">
              <option>All products</option>
              <option>Books</option>
              <option>Tools</option></select
            ><label
              >Sort by<select name="sort">
                <option>Recommended</option>
                <option>Newest first</option>
                <option>Price: low to high</option>
              </select></label
            >
            <p class="demo-hint">
              Narrow the collection, then return to browsing. Your selection is reported below the
              preview.
            </p>
            <button type="submit">Apply filters</button>
          </form>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Filter the collection',
  description: 'Choose a category and sort order for the collection.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    body.querySelector('form').addEventListener(
      'submit',
      event => {
        event.preventDefault()
        const values = new FormData(event.currentTarget)
        const category = values.get('category')
        const sort = values.get('sort')
        document.getElementById('demo-result').textContent =
          'Selected category:' + ' ' + category + ' · ' + sort
        drawer.setOpen(false)
      },
      { signal: lifecycle.signal }
    )
    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <form data-demo-form data-drawer-no-drag>
            <label for="category">Category</label
            ><select id="category" name="category">
              <option>All products</option>
              <option>Books</option>
              <option>Tools</option></select
            ><label
              >Sort by<select name="sort">
                <option>Recommended</option>
                <option>Newest first</option>
                <option>Price: low to high</option>
              </select></label
            >
            <p class="demo-hint">
              Narrow the collection, then return to browsing. Your selection is reported below the
              preview.
            </p>
            <button type="submit">Apply filters</button>
          </form>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Filter the collection',
        description: 'Choose a category and sort order for the collection.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          body.querySelector('form').addEventListener(
            'submit',
            event => {
              event.preventDefault()
              const values = new FormData(event.currentTarget)
              const category = values.get('category')
              const sort = values.get('sort')
              document.getElementById('demo-result').textContent =
                'Selected category:' + ' ' + category + ' · ' + sort
              drawer.setOpen(false)
            },
            { signal: lifecycle.signal }
          )
          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
08 / right

Read more without losing your place

Read more without losing your placeLive · @samline/drawer

Your page, uninterrupted

Keep the context.

Scroll a long panel independently of the page. Its close action stays within reach.

Closed

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body" tabindex="0" role="region" aria-label="Drawer reading area">
          <section>
            <h3>Project overview</h3>
            <p>
              Start a hand-off with the purpose of the project, its intended audience and the
              decisions already agreed with the team. Link the source repository and identify which
              journeys must work before release.
            </p>
          </section>
          <section>
            <h3>Run the project</h3>
            <p>
              Record the supported runtime, the package-manager command, the development command and
              the production build command. List required environment variable names, with safe
              sample values rather than credentials. Ask a teammate to try these steps on a fresh
              checkout.
            </p>
          </section>
          <section>
            <h3>Design assets</h3>
            <p>
              Point to the approved fonts, color tokens, icons and image sources. Note license
              requirements and where editable assets live. Keep the component inventory close to the
              design files so changes can be made in the right shared owner.
            </p>
          </section>
          <section>
            <h3>Keyboard review</h3>
            <p>
              Walk through the main journey with Tab, Shift+Tab, Enter and Escape. Check visible
              focus, names on icon buttons, form labels and focus restoration after overlays close.
              Include narrow layouts and enlarged text in the review.
            </p>
          </section>
          <section>
            <h3>Forms and error states</h3>
            <p>
              Document required fields, validation messages, successful submissions and recovery
              from a failed request. Use representative empty and long values. Make the result
              visible and distinguish a local demonstration from a connected service.
            </p>
          </section>
          <section>
            <h3>Loading and content</h3>
            <p>
              Explain empty, loading, error and populated states. Reserve space for media, keep
              useful content readable without JavaScript where practical, and identify who can edit
              public copy. Remove placeholders before release.
            </p>
          </section>
          <section>
            <h3>Deployment checklist</h3>
            <p>
              Record the build artifact, public base path, redirect requirements and rollback
              procedure. Verify a production build, internal anchors and important external
              destinations. Confirm the deployed revision before calling a release complete.
            </p>
          </section>
          <section>
            <h3>Ownership and follow-up</h3>
            <p>
              Name the maintainer for code, content and releases. Capture known limits honestly,
              link the relevant checks, and agree how future package or design changes update
              examples and documentation. A useful hand-off lets the next person repeat the work.
            </p>
          </section>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'right',
  title: 'Project hand-off guide',
  description: 'Read the practical steps for handing a project to its next maintainer.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        right: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body" tabindex="0" role="region" aria-label="Drawer reading area">
          <section>
            <h3>Project overview</h3>
            <p>
              Start a hand-off with the purpose of the project, its intended audience and the
              decisions already agreed with the team. Link the source repository and identify which
              journeys must work before release.
            </p>
          </section>
          <section>
            <h3>Run the project</h3>
            <p>
              Record the supported runtime, the package-manager command, the development command and
              the production build command. List required environment variable names, with safe
              sample values rather than credentials. Ask a teammate to try these steps on a fresh
              checkout.
            </p>
          </section>
          <section>
            <h3>Design assets</h3>
            <p>
              Point to the approved fonts, color tokens, icons and image sources. Note license
              requirements and where editable assets live. Keep the component inventory close to the
              design files so changes can be made in the right shared owner.
            </p>
          </section>
          <section>
            <h3>Keyboard review</h3>
            <p>
              Walk through the main journey with Tab, Shift+Tab, Enter and Escape. Check visible
              focus, names on icon buttons, form labels and focus restoration after overlays close.
              Include narrow layouts and enlarged text in the review.
            </p>
          </section>
          <section>
            <h3>Forms and error states</h3>
            <p>
              Document required fields, validation messages, successful submissions and recovery
              from a failed request. Use representative empty and long values. Make the result
              visible and distinguish a local demonstration from a connected service.
            </p>
          </section>
          <section>
            <h3>Loading and content</h3>
            <p>
              Explain empty, loading, error and populated states. Reserve space for media, keep
              useful content readable without JavaScript where practical, and identify who can edit
              public copy. Remove placeholders before release.
            </p>
          </section>
          <section>
            <h3>Deployment checklist</h3>
            <p>
              Record the build artifact, public base path, redirect requirements and rollback
              procedure. Verify a production build, internal anchors and important external
              destinations. Confirm the deployed revision before calling a release complete.
            </p>
          </section>
          <section>
            <h3>Ownership and follow-up</h3>
            <p>
              Name the maintainer for code, content and releases. Capture known limits honestly,
              link the relevant checks, and agree how future package or design changes update
              examples and documentation. A useful hand-off lets the next person repeat the work.
            </p>
          </section>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'right',
        title: 'Project hand-off guide',
        description: 'Read the practical steps for handing a project to its next maintainer.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body" tabindex="0" role="region" aria-label="Drawer reading area">
          <section>
            <h3>Project overview</h3>
            <p>
              Start a hand-off with the purpose of the project, its intended audience and the
              decisions already agreed with the team. Link the source repository and identify which
              journeys must work before release.
            </p>
          </section>
          <section>
            <h3>Run the project</h3>
            <p>
              Record the supported runtime, the package-manager command, the development command and
              the production build command. List required environment variable names, with safe
              sample values rather than credentials. Ask a teammate to try these steps on a fresh
              checkout.
            </p>
          </section>
          <section>
            <h3>Design assets</h3>
            <p>
              Point to the approved fonts, color tokens, icons and image sources. Note license
              requirements and where editable assets live. Keep the component inventory close to the
              design files so changes can be made in the right shared owner.
            </p>
          </section>
          <section>
            <h3>Keyboard review</h3>
            <p>
              Walk through the main journey with Tab, Shift+Tab, Enter and Escape. Check visible
              focus, names on icon buttons, form labels and focus restoration after overlays close.
              Include narrow layouts and enlarged text in the review.
            </p>
          </section>
          <section>
            <h3>Forms and error states</h3>
            <p>
              Document required fields, validation messages, successful submissions and recovery
              from a failed request. Use representative empty and long values. Make the result
              visible and distinguish a local demonstration from a connected service.
            </p>
          </section>
          <section>
            <h3>Loading and content</h3>
            <p>
              Explain empty, loading, error and populated states. Reserve space for media, keep
              useful content readable without JavaScript where practical, and identify who can edit
              public copy. Remove placeholders before release.
            </p>
          </section>
          <section>
            <h3>Deployment checklist</h3>
            <p>
              Record the build artifact, public base path, redirect requirements and rollback
              procedure. Verify a production build, internal anchors and important external
              destinations. Confirm the deployed revision before calling a release complete.
            </p>
          </section>
          <section>
            <h3>Ownership and follow-up</h3>
            <p>
              Name the maintainer for code, content and releases. Capture known limits honestly,
              link the relevant checks, and agree how future package or design changes update
              examples and documentation. A useful hand-off lets the next person repeat the work.
            </p>
          </section>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'right',
  title: 'Project hand-off guide',
  description: 'Read the practical steps for handing a project to its next maintainer.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        right: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body" tabindex="0" role="region" aria-label="Drawer reading area">
          <section>
            <h3>Project overview</h3>
            <p>
              Start a hand-off with the purpose of the project, its intended audience and the
              decisions already agreed with the team. Link the source repository and identify which
              journeys must work before release.
            </p>
          </section>
          <section>
            <h3>Run the project</h3>
            <p>
              Record the supported runtime, the package-manager command, the development command and
              the production build command. List required environment variable names, with safe
              sample values rather than credentials. Ask a teammate to try these steps on a fresh
              checkout.
            </p>
          </section>
          <section>
            <h3>Design assets</h3>
            <p>
              Point to the approved fonts, color tokens, icons and image sources. Note license
              requirements and where editable assets live. Keep the component inventory close to the
              design files so changes can be made in the right shared owner.
            </p>
          </section>
          <section>
            <h3>Keyboard review</h3>
            <p>
              Walk through the main journey with Tab, Shift+Tab, Enter and Escape. Check visible
              focus, names on icon buttons, form labels and focus restoration after overlays close.
              Include narrow layouts and enlarged text in the review.
            </p>
          </section>
          <section>
            <h3>Forms and error states</h3>
            <p>
              Document required fields, validation messages, successful submissions and recovery
              from a failed request. Use representative empty and long values. Make the result
              visible and distinguish a local demonstration from a connected service.
            </p>
          </section>
          <section>
            <h3>Loading and content</h3>
            <p>
              Explain empty, loading, error and populated states. Reserve space for media, keep
              useful content readable without JavaScript where practical, and identify who can edit
              public copy. Remove placeholders before release.
            </p>
          </section>
          <section>
            <h3>Deployment checklist</h3>
            <p>
              Record the build artifact, public base path, redirect requirements and rollback
              procedure. Verify a production build, internal anchors and important external
              destinations. Confirm the deployed revision before calling a release complete.
            </p>
          </section>
          <section>
            <h3>Ownership and follow-up</h3>
            <p>
              Name the maintainer for code, content and releases. Capture known limits honestly,
              link the relevant checks, and agree how future package or design changes update
              examples and documentation. A useful hand-off lets the next person repeat the work.
            </p>
          </section>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'right',
        title: 'Project hand-off guide',
        description: 'Read the practical steps for handing a project to its next maintainer.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
09 / right

Keep the page interactive

Keep the page interactiveLive · @samline/drawer

LAYOUT INSPECTOR

Work beside your canvas.

A non-modal inspector has no backdrop or focus trap. You can still use the page while it is open.

Closed

Clear page-action feedback and hide the canvas grid on close. Uncheck to retain the inspector settings and feedback between attempts. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Toggle the canvas grid, then use the page action without closing the inspector. No backdrop, focus trap or page scroll lock.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>
      <button type="button" id="page-action">Try a page action</button>
      <div id="canvas" class="demo-canvas">
        <h2>A canvas you can keep editing</h2>
        <p>
          Use the inspector to reveal its layout grid, or try the page action while the inspector
          stays open.
        </p>
      </div>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">LAYOUT INSPECTOR</p>
          <h3>Work beside your canvas.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Selected: Hero section</strong>
                <p>Editing the hero of a product landing page.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="3" y="3" width="18" height="18" rx="2" />
                  <path d="M3 9h18M9 21V9" /></svg
              ></span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Canvas layout</strong>
                <p>Toggle the layout grid while the canvas stays interactive.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg
              ></span>
            </div>
          </div>
          <label class="demo-field-inline" data-drawer-no-drag
            ><input type="checkbox" data-demo-grid />Show canvas grid</label
          >
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-body label.demo-field-inline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.demo-body .demo-field-inline input {
  width: 1.125rem;
  height: 1.125rem;
  padding: 0;
  flex-shrink: 0;
}
.demo-canvas {
  margin-top: 1.5rem;
  padding: 2rem;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
}
.demo-canvas[data-grid] {
  background-image:
    linear-gradient(#d9cbd5 0.0625rem, transparent 0.0625rem),
    linear-gradient(90deg, #d9cbd5 0.0625rem, transparent 0.0625rem);
  background-size: 1.5rem 1.5rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'right',
  title: 'Canvas inspector',
  description: 'Inspect the hero layout while the canvas remains interactive.',
  autoFocus: false,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const canvas = document.getElementById('canvas')
    const grid = body.querySelector('[data-demo-grid]')
    grid.checked = canvas.hasAttribute('data-grid')
    grid.addEventListener('change', () => canvas.toggleAttribute('data-grid', grid.checked), {
      signal: lifecycle.signal,
    })

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  modal: false,
  overlay: false,
})

document.getElementById('page-action').addEventListener(
  'click',
  () => {
    document.getElementById('demo-result').textContent = 'The page is still interactive.'
  },
  { signal: lifecycle.signal }
)

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()

    document.getElementById('canvas').removeAttribute('data-grid')
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        right: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-body label.demo-field-inline {
        display: flex;
        align-items: center;
        gap: 0.75rem;
      }
      .demo-body .demo-field-inline input {
        width: 1.125rem;
        height: 1.125rem;
        padding: 0;
        flex-shrink: 0;
      }
      .demo-canvas {
        margin-top: 1.5rem;
        padding: 2rem;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
      }
      .demo-canvas[data-grid] {
        background-image:
          linear-gradient(#d9cbd5 0.0625rem, transparent 0.0625rem),
          linear-gradient(90deg, #d9cbd5 0.0625rem, transparent 0.0625rem);
        background-size: 1.5rem 1.5rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>
      <button type="button" id="page-action">Try a page action</button>
      <div id="canvas" class="demo-canvas">
        <h2>A canvas you can keep editing</h2>
        <p>
          Use the inspector to reveal its layout grid, or try the page action while the inspector
          stays open.
        </p>
      </div>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">LAYOUT INSPECTOR</p>
          <h3>Work beside your canvas.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Selected: Hero section</strong>
                <p>Editing the hero of a product landing page.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="3" y="3" width="18" height="18" rx="2" />
                  <path d="M3 9h18M9 21V9" /></svg
              ></span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Canvas layout</strong>
                <p>Toggle the layout grid while the canvas stays interactive.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg
              ></span>
            </div>
          </div>
          <label class="demo-field-inline" data-drawer-no-drag
            ><input type="checkbox" data-demo-grid />Show canvas grid</label
          >
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'right',
        title: 'Canvas inspector',
        description: 'Inspect the hero layout while the canvas remains interactive.',
        autoFocus: false,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const canvas = document.getElementById('canvas')
          const grid = body.querySelector('[data-demo-grid]')
          grid.checked = canvas.hasAttribute('data-grid')
          grid.addEventListener('change', () => canvas.toggleAttribute('data-grid', grid.checked), {
            signal: lifecycle.signal,
          })

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        modal: false,
        overlay: false,
      })

      document.getElementById('page-action').addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent = 'The page is still interactive.'
        },
        { signal: lifecycle.signal }
      )

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()

          document.getElementById('canvas').removeAttribute('data-grid')
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>
      <button type="button" id="page-action">Try a page action</button>
      <div id="canvas" class="demo-canvas">
        <h2>A canvas you can keep editing</h2>
        <p>
          Use the inspector to reveal its layout grid, or try the page action while the inspector
          stays open.
        </p>
      </div>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">LAYOUT INSPECTOR</p>
          <h3>Work beside your canvas.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Selected: Hero section</strong>
                <p>Editing the hero of a product landing page.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="3" y="3" width="18" height="18" rx="2" />
                  <path d="M3 9h18M9 21V9" /></svg
              ></span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Canvas layout</strong>
                <p>Toggle the layout grid while the canvas stays interactive.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg
              ></span>
            </div>
          </div>
          <label class="demo-field-inline" data-drawer-no-drag
            ><input type="checkbox" data-demo-grid />Show canvas grid</label
          >
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-body label.demo-field-inline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.demo-body .demo-field-inline input {
  width: 1.125rem;
  height: 1.125rem;
  padding: 0;
  flex-shrink: 0;
}
.demo-canvas {
  margin-top: 1.5rem;
  padding: 2rem;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
}
.demo-canvas[data-grid] {
  background-image:
    linear-gradient(#d9cbd5 0.0625rem, transparent 0.0625rem),
    linear-gradient(90deg, #d9cbd5 0.0625rem, transparent 0.0625rem);
  background-size: 1.5rem 1.5rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'right',
  title: 'Canvas inspector',
  description: 'Inspect the hero layout while the canvas remains interactive.',
  autoFocus: false,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const canvas = document.getElementById('canvas')
    const grid = body.querySelector('[data-demo-grid]')
    grid.checked = canvas.hasAttribute('data-grid')
    grid.addEventListener('change', () => canvas.toggleAttribute('data-grid', grid.checked), {
      signal: lifecycle.signal,
    })

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  modal: false,
  overlay: false,
})

document.getElementById('page-action').addEventListener(
  'click',
  () => {
    document.getElementById('demo-result').textContent = 'The page is still interactive.'
  },
  { signal: lifecycle.signal }
)

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()

    document.getElementById('canvas').removeAttribute('data-grid')
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        right: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-body label.demo-field-inline {
        display: flex;
        align-items: center;
        gap: 0.75rem;
      }
      .demo-body .demo-field-inline input {
        width: 1.125rem;
        height: 1.125rem;
        padding: 0;
        flex-shrink: 0;
      }
      .demo-canvas {
        margin-top: 1.5rem;
        padding: 2rem;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
      }
      .demo-canvas[data-grid] {
        background-image:
          linear-gradient(#d9cbd5 0.0625rem, transparent 0.0625rem),
          linear-gradient(90deg, #d9cbd5 0.0625rem, transparent 0.0625rem);
        background-size: 1.5rem 1.5rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>
      <button type="button" id="page-action">Try a page action</button>
      <div id="canvas" class="demo-canvas">
        <h2>A canvas you can keep editing</h2>
        <p>
          Use the inspector to reveal its layout grid, or try the page action while the inspector
          stays open.
        </p>
      </div>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">LAYOUT INSPECTOR</p>
          <h3>Work beside your canvas.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Selected: Hero section</strong>
                <p>Editing the hero of a product landing page.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="3" y="3" width="18" height="18" rx="2" />
                  <path d="M3 9h18M9 21V9" /></svg
              ></span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Canvas layout</strong>
                <p>Toggle the layout grid while the canvas stays interactive.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg
              ></span>
            </div>
          </div>
          <label class="demo-field-inline" data-drawer-no-drag
            ><input type="checkbox" data-demo-grid />Show canvas grid</label
          >
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'right',
        title: 'Canvas inspector',
        description: 'Inspect the hero layout while the canvas remains interactive.',
        autoFocus: false,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const canvas = document.getElementById('canvas')
          const grid = body.querySelector('[data-demo-grid]')
          grid.checked = canvas.hasAttribute('data-grid')
          grid.addEventListener('change', () => canvas.toggleAttribute('data-grid', grid.checked), {
            signal: lifecycle.signal,
          })

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        modal: false,
        overlay: false,
      })

      document.getElementById('page-action').addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent = 'The page is still interactive.'
        },
        { signal: lifecycle.signal }
      )

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()

          document.getElementById('canvas').removeAttribute('data-grid')
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
10 / bottom

Drag the handle, not the content

Drag the handle, not the contentLive · @samline/drawer

IDEAS / QUICK NOTE

Catch an idea before it goes.

Select text and use inputs normally. Only a drag that starts on the handle moves this sheet.

Closed

Drag only the native handle. Content gestures and keyboard controls remain independent.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">IDEAS / QUICK NOTE</p>
          <h3>Catch an idea before it goes.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Launch review checklist</strong>
                <p>
                  Check keyboard navigation, narrow layouts and the installation snippet. Add your
                  review notes below.
                </p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" /></svg
              ></span>
            </div>
          </div>

          <label data-drawer-no-drag
            >Your notes<textarea placeholder="Select text or write a note…"></textarea>
          </label>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Review notes',
  description: 'Write launch-review feedback while keeping your checklist close.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  handleOnly: true,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">IDEAS / QUICK NOTE</p>
          <h3>Catch an idea before it goes.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Launch review checklist</strong>
                <p>
                  Check keyboard navigation, narrow layouts and the installation snippet. Add your
                  review notes below.
                </p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" /></svg
              ></span>
            </div>
          </div>

          <label data-drawer-no-drag
            >Your notes<textarea placeholder="Select text or write a note…"></textarea>
          </label>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Review notes',
        description: 'Write launch-review feedback while keeping your checklist close.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        handleOnly: true,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">IDEAS / QUICK NOTE</p>
          <h3>Catch an idea before it goes.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Launch review checklist</strong>
                <p>
                  Check keyboard navigation, narrow layouts and the installation snippet. Add your
                  review notes below.
                </p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" /></svg
              ></span>
            </div>
          </div>

          <label data-drawer-no-drag
            >Your notes<textarea placeholder="Select text or write a note…"></textarea>
          </label>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Review notes',
  description: 'Write launch-review feedback while keeping your checklist close.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  handleOnly: true,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">IDEAS / QUICK NOTE</p>
          <h3>Catch an idea before it goes.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Launch review checklist</strong>
                <p>
                  Check keyboard navigation, narrow layouts and the installation snippet. Add your
                  review notes below.
                </p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" /></svg
              ></span>
            </div>
          </div>

          <label data-drawer-no-drag
            >Your notes<textarea placeholder="Select text or write a note…"></textarea>
          </label>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Review notes',
        description: 'Write launch-review feedback while keeping your checklist close.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        handleOnly: true,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
11 / bottom

Update content in place

Update content in placeLive · @samline/drawer

ORDER STUDIO-1042

Follow the next step.

Load another detail into the same instance with update(). No second drawer or global event handler.

Closed

Restore the original order information and its update button when you reopen. Uncheck to keep the changed title and content. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">ORDER STUDIO-1042</p>
          <h3>Follow the next step.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Order confirmed</strong>
                <p>Your tote and notebook are being prepared.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="m5 12 5 5L20 7" /></svg
              ></span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Next: packed for delivery</strong>
                <p>See when your items are packed and what happens next.</p>
              </div>
              <span>02</span>
            </div>
          </div>

          <button type="button" data-demo-update data-drawer-no-drag>Show packing update</button>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Order STUDIO-1042',
  description: 'Review your order confirmation, then load its packing update.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    body.querySelector('[data-demo-update]').addEventListener(
      'click',
      () => {
        drawer.update({
          title: 'Packed and ready to go',
          content:
            'Order STUDIO-1042 is packed: one Everyday tote and one Studio notebook. Standard delivery takes 3–5 business days. Next step: hand-off to the carrier.',
        })
      },
      { signal: lifecycle.signal }
    )
    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">ORDER STUDIO-1042</p>
          <h3>Follow the next step.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Order confirmed</strong>
                <p>Your tote and notebook are being prepared.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="m5 12 5 5L20 7" /></svg
              ></span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Next: packed for delivery</strong>
                <p>See when your items are packed and what happens next.</p>
              </div>
              <span>02</span>
            </div>
          </div>

          <button type="button" data-demo-update data-drawer-no-drag>Show packing update</button>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Order STUDIO-1042',
        description: 'Review your order confirmation, then load its packing update.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          body.querySelector('[data-demo-update]').addEventListener(
            'click',
            () => {
              drawer.update({
                title: 'Packed and ready to go',
                content:
                  'Order STUDIO-1042 is packed: one Everyday tote and one Studio notebook. Standard delivery takes 3–5 business days. Next step: hand-off to the carrier.',
              })
            },
            { signal: lifecycle.signal }
          )
          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">ORDER STUDIO-1042</p>
          <h3>Follow the next step.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Order confirmed</strong>
                <p>Your tote and notebook are being prepared.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="m5 12 5 5L20 7" /></svg
              ></span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Next: packed for delivery</strong>
                <p>See when your items are packed and what happens next.</p>
              </div>
              <span>02</span>
            </div>
          </div>

          <button type="button" data-demo-update data-drawer-no-drag>Show packing update</button>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Order STUDIO-1042',
  description: 'Review your order confirmation, then load its packing update.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    body.querySelector('[data-demo-update]').addEventListener(
      'click',
      () => {
        drawer.update({
          title: 'Packed and ready to go',
          content:
            'Order STUDIO-1042 is packed: one Everyday tote and one Studio notebook. Standard delivery takes 3–5 business days. Next step: hand-off to the carrier.',
        })
      },
      { signal: lifecycle.signal }
    )
    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">ORDER STUDIO-1042</p>
          <h3>Follow the next step.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Order confirmed</strong>
                <p>Your tote and notebook are being prepared.</p>
              </div>
              <span
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="m5 12 5 5L20 7" /></svg
              ></span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Next: packed for delivery</strong>
                <p>See when your items are packed and what happens next.</p>
              </div>
              <span>02</span>
            </div>
          </div>

          <button type="button" data-demo-update data-drawer-no-drag>Show packing update</button>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Order STUDIO-1042',
        description: 'Review your order confirmation, then load its packing update.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          body.querySelector('[data-demo-update]').addEventListener(
            'click',
            () => {
              drawer.update({
                title: 'Packed and ready to go',
                content:
                  'Order STUDIO-1042 is packed: one Everyday tote and one Studio notebook. Standard delivery takes 3–5 business days. Next step: hand-off to the carrier.',
              })
            },
            { signal: lifecycle.signal }
          )
          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
12 / bottom

Choose the size explicitly

Choose the size explicitlyLive · @samline/drawer

SAMPLE BOARDING PASS · ST204

Your flight, at a glance.

Compact and expanded actions call setActiveSnapPoint(). The native handle and gestures still work.

Closed

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <div class="demo-actions" data-drawer-no-drag>
            <button type="button" data-demo-compact>Compact</button
            ><button type="button" data-demo-expanded>Expanded</button>
          </div>
          <p class="demo-kicker">SAMPLE BOARDING PASS · ST204</p>
          <h3>Your flight, at a glance.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Mexico City → Oaxaca</strong>
                <p>Terminal 2 · Gate 12 · Economy</p>
              </div>
              <span>08:15</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Boarding</strong>
                <p>Have your travel document ready at the gate.</p>
              </div>
              <span>07:40</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Cabin baggage</strong>
                <p>One cabin bag and one personal item.</p>
              </div>
              <span>2 items</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Before departure</strong>
                <p>
                  Check the airport screens for gate changes. This is a fictional sample boarding
                  pass.
                </p>
              </div>
              <span>ST204</span>
            </div>
          </div>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}
.demo-drawer {
  height: 100dvh;
  max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
  padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Boarding pass',
  description: 'View boarding time and baggage details for this fictional sample flight.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    body
      .querySelector('[data-demo-compact]')
      .addEventListener('click', () => drawer.setActiveSnapPoint(0.45), {
        signal: lifecycle.signal,
      })
    body
      .querySelector('[data-demo-expanded]')
      .addEventListener('click', () => drawer.setActiveSnapPoint(1), { signal: lifecycle.signal })
    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  snapPoints: [0.45, 0.72, 1],
  activeSnapPoint: 0.45,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }
      .demo-drawer {
        height: 100dvh;
        max-height: 100dvh;
      }
      .demo-drawer[data-state='open'] {
        padding-bottom: calc(2rem + var(--initial-transform, 0rem));
      }
      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <div class="demo-actions" data-drawer-no-drag>
            <button type="button" data-demo-compact>Compact</button
            ><button type="button" data-demo-expanded>Expanded</button>
          </div>
          <p class="demo-kicker">SAMPLE BOARDING PASS · ST204</p>
          <h3>Your flight, at a glance.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Mexico City → Oaxaca</strong>
                <p>Terminal 2 · Gate 12 · Economy</p>
              </div>
              <span>08:15</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Boarding</strong>
                <p>Have your travel document ready at the gate.</p>
              </div>
              <span>07:40</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Cabin baggage</strong>
                <p>One cabin bag and one personal item.</p>
              </div>
              <span>2 items</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Before departure</strong>
                <p>
                  Check the airport screens for gate changes. This is a fictional sample boarding
                  pass.
                </p>
              </div>
              <span>ST204</span>
            </div>
          </div>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Boarding pass',
        description: 'View boarding time and baggage details for this fictional sample flight.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          body
            .querySelector('[data-demo-compact]')
            .addEventListener('click', () => drawer.setActiveSnapPoint(0.45), {
              signal: lifecycle.signal,
            })
          body
            .querySelector('[data-demo-expanded]')
            .addEventListener('click', () => drawer.setActiveSnapPoint(1), {
              signal: lifecycle.signal,
            })
          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        snapPoints: [0.45, 0.72, 1],
        activeSnapPoint: 0.45,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <div class="demo-actions" data-drawer-no-drag>
            <button type="button" data-demo-compact>Compact</button
            ><button type="button" data-demo-expanded>Expanded</button>
          </div>
          <p class="demo-kicker">SAMPLE BOARDING PASS · ST204</p>
          <h3>Your flight, at a glance.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Mexico City → Oaxaca</strong>
                <p>Terminal 2 · Gate 12 · Economy</p>
              </div>
              <span>08:15</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Boarding</strong>
                <p>Have your travel document ready at the gate.</p>
              </div>
              <span>07:40</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Cabin baggage</strong>
                <p>One cabin bag and one personal item.</p>
              </div>
              <span>2 items</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Before departure</strong>
                <p>
                  Check the airport screens for gate changes. This is a fictional sample boarding
                  pass.
                </p>
              </div>
              <span>ST204</span>
            </div>
          </div>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}
.demo-drawer {
  height: 100dvh;
  max-height: 100dvh;
}
.demo-drawer[data-state='open'] {
  padding-bottom: calc(2rem + var(--initial-transform, 0rem));
}
.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Boarding pass',
  description: 'View boarding time and baggage details for this fictional sample flight.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    body
      .querySelector('[data-demo-compact]')
      .addEventListener('click', () => drawer.setActiveSnapPoint(0.45), {
        signal: lifecycle.signal,
      })
    body
      .querySelector('[data-demo-expanded]')
      .addEventListener('click', () => drawer.setActiveSnapPoint(1), { signal: lifecycle.signal })
    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  snapPoints: [0.45, 0.72, 1],
  activeSnapPoint: 0.45,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }
      .demo-drawer {
        height: 100dvh;
        max-height: 100dvh;
      }
      .demo-drawer[data-state='open'] {
        padding-bottom: calc(2rem + var(--initial-transform, 0rem));
      }
      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <div class="demo-actions" data-drawer-no-drag>
            <button type="button" data-demo-compact>Compact</button
            ><button type="button" data-demo-expanded>Expanded</button>
          </div>
          <p class="demo-kicker">SAMPLE BOARDING PASS · ST204</p>
          <h3>Your flight, at a glance.</h3>
          <div class="demo-scene">
            <div class="demo-scene-row">
              <div>
                <strong>Mexico City → Oaxaca</strong>
                <p>Terminal 2 · Gate 12 · Economy</p>
              </div>
              <span>08:15</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Boarding</strong>
                <p>Have your travel document ready at the gate.</p>
              </div>
              <span>07:40</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Cabin baggage</strong>
                <p>One cabin bag and one personal item.</p>
              </div>
              <span>2 items</span>
            </div>
            <div class="demo-scene-row">
              <div>
                <strong>Before departure</strong>
                <p>
                  Check the airport screens for gate changes. This is a fictional sample boarding
                  pass.
                </p>
              </div>
              <span>ST204</span>
            </div>
          </div>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Boarding pass',
        description: 'View boarding time and baggage details for this fictional sample flight.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          body
            .querySelector('[data-demo-compact]')
            .addEventListener('click', () => drawer.setActiveSnapPoint(0.45), {
              signal: lifecycle.signal,
            })
          body
            .querySelector('[data-demo-expanded]')
            .addEventListener('click', () => drawer.setActiveSnapPoint(1), {
              signal: lifecycle.signal,
            })
          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        snapPoints: [0.45, 0.72, 1],
        activeSnapPoint: 0.45,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
13 / right

An account menu that travels with you

An account menu that travels with youLive · @samline/drawer

SIGNED IN AS ALEX

Your spaces. One account.

Switch workspaces or open account actions without losing the current page.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">SIGNED IN AS ALEX</p>
          <h3>Your spaces. One account.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="Your spaces. One account."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Personal workspace">
              <span class="demo-menu-icon" aria-hidden="true">A</span
              ><span class="demo-menu-copy"
                ><strong>Personal workspace</strong><span>Your private projects</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Studio workspace">
              <span class="demo-menu-icon" aria-hidden="true">S</span
              ><span class="demo-menu-copy"
                ><strong>Studio workspace</strong><span>Shared with 6 teammates</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Account settings">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Account settings</strong><span>Profile and preferences</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Keep private projects separate from shared team work.</p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'right',
  title: 'Your account',
  description: 'Choose your personal or team workspace, or open account settings.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        right: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">SIGNED IN AS ALEX</p>
          <h3>Your spaces. One account.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="Your spaces. One account."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Personal workspace">
              <span class="demo-menu-icon" aria-hidden="true">A</span
              ><span class="demo-menu-copy"
                ><strong>Personal workspace</strong><span>Your private projects</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Studio workspace">
              <span class="demo-menu-icon" aria-hidden="true">S</span
              ><span class="demo-menu-copy"
                ><strong>Studio workspace</strong><span>Shared with 6 teammates</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Account settings">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Account settings</strong><span>Profile and preferences</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Keep private projects separate from shared team work.</p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'right',
        title: 'Your account',
        description: 'Choose your personal or team workspace, or open account settings.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">SIGNED IN AS ALEX</p>
          <h3>Your spaces. One account.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="Your spaces. One account."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Personal workspace">
              <span class="demo-menu-icon" aria-hidden="true">A</span
              ><span class="demo-menu-copy"
                ><strong>Personal workspace</strong><span>Your private projects</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Studio workspace">
              <span class="demo-menu-icon" aria-hidden="true">S</span
              ><span class="demo-menu-copy"
                ><strong>Studio workspace</strong><span>Shared with 6 teammates</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Account settings">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Account settings</strong><span>Profile and preferences</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Keep private projects separate from shared team work.</p>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'right',
  title: 'Your account',
  description: 'Choose your personal or team workspace, or open account settings.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        right: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">SIGNED IN AS ALEX</p>
          <h3>Your spaces. One account.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="Your spaces. One account."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Personal workspace">
              <span class="demo-menu-icon" aria-hidden="true">A</span
              ><span class="demo-menu-copy"
                ><strong>Personal workspace</strong><span>Your private projects</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Studio workspace">
              <span class="demo-menu-icon" aria-hidden="true">S</span
              ><span class="demo-menu-copy"
                ><strong>Studio workspace</strong><span>Shared with 6 teammates</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Account settings">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Account settings</strong><span>Profile and preferences</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Keep private projects separate from shared team work.</p>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'right',
        title: 'Your account',
        description: 'Choose your personal or team workspace, or open account settings.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
14 / bottom

A file action sheet, ready for touch

A file action sheet, ready for touchLive · @samline/drawer

PROJECT BRIEF.PDF · 2.4 MB

Keep the file. Open the possibilities.

Group contextual actions in a comfortable sheet. Report the selection back to the page.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Real package behavior: drag to dismiss, modal focus, Escape and a close button. Your CSS sets the shape.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">PROJECT BRIEF.PDF · 2.4 MB</p>
          <h3>Keep the file. Open the possibilities.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="Keep the file. Open the possibilities."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Add to favorites">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2L12 17.3l-5.6 2.9 1.1-6.2L3 9.6l6.2-.9Z"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Add to favorites</strong><span>Keep it close for later</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Make a copy">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="8" y="8" width="13" height="13" rx="2" />
                  <path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Make a copy</strong><span>Start another version</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Move to a folder">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Move to a folder</strong><span>Put everything in its place</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Choose what to do with Project brief.pdf.</p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Project brief.pdf',
  description: 'Choose a contextual action for this document.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">PROJECT BRIEF.PDF · 2.4 MB</p>
          <h3>Keep the file. Open the possibilities.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="Keep the file. Open the possibilities."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Add to favorites">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2L12 17.3l-5.6 2.9 1.1-6.2L3 9.6l6.2-.9Z"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Add to favorites</strong><span>Keep it close for later</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Make a copy">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="8" y="8" width="13" height="13" rx="2" />
                  <path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Make a copy</strong><span>Start another version</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Move to a folder">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Move to a folder</strong><span>Put everything in its place</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Choose what to do with Project brief.pdf.</p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Project brief.pdf',
        description: 'Choose a contextual action for this document.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">PROJECT BRIEF.PDF · 2.4 MB</p>
          <h3>Keep the file. Open the possibilities.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="Keep the file. Open the possibilities."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Add to favorites">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2L12 17.3l-5.6 2.9 1.1-6.2L3 9.6l6.2-.9Z"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Add to favorites</strong><span>Keep it close for later</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Make a copy">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="8" y="8" width="13" height="13" rx="2" />
                  <path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Make a copy</strong><span>Start another version</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Move to a folder">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Move to a folder</strong><span>Put everything in its place</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Choose what to do with Project brief.pdf.</p>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Project brief.pdf',
  description: 'Choose a contextual action for this document.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">PROJECT BRIEF.PDF · 2.4 MB</p>
          <h3>Keep the file. Open the possibilities.</h3>

          <div
            class="demo-menu"
            role="group"
            aria-label="Keep the file. Open the possibilities."
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Add to favorites">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="m12 3 2.8 5.7 6.2.9-4.5 4.4 1.1 6.2L12 17.3l-5.6 2.9 1.1-6.2L3 9.6l6.2-.9Z"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Add to favorites</strong><span>Keep it close for later</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Make a copy">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <rect x="8" y="8" width="13" height="13" rx="2" />
                  <path d="M16 8V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h3" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Make a copy</strong><span>Start another version</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Move to a folder">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path
                    d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"
                  /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Move to a folder</strong><span>Put everything in its place</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">Choose what to do with Project brief.pdf.</p>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Project brief.pdf',
        description: 'Choose a contextual action for this document.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
15 / bottom

Make consequential choices explicit

Make consequential choices explicitLive · @samline/drawer

UNSAVED DRAFT

Keep what you have started?

An unsaved draft needs a decision. Outside clicks and gestures cannot dismiss this confirmation.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">UNSAVED DRAFT</p>
          <h3>Keep what you have started?</h3>

          <div class="demo-scene">
            <div class="demo-scene-row">
              <p>
                Launch note: The new collection goes live on Friday. Add the product screenshots
                before the review.
              </p>
            </div>
          </div>
          <div
            class="demo-menu"
            role="group"
            aria-label="Keep what you have started?"
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Save draft">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="m5 12 5 5L20 7" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Save draft</strong><span>Keep your work for later</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Discard draft">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M6 6l12 12M18 6 6 18" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Discard draft</strong><span>Close without saving</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Continue editing">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M9 14 4 9l5-5" />
                  <path d="M4 9h11a5 5 0 0 1 0 10h-3" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Continue editing</strong><span>Return to your page</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">
            Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
          </p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Unsaved launch note',
  description: 'Choose whether to keep your draft, discard it or continue editing.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  dismissible: false,
  closeButton: false,
  showHandle: false,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">UNSAVED DRAFT</p>
          <h3>Keep what you have started?</h3>

          <div class="demo-scene">
            <div class="demo-scene-row">
              <p>
                Launch note: The new collection goes live on Friday. Add the product screenshots
                before the review.
              </p>
            </div>
          </div>
          <div
            class="demo-menu"
            role="group"
            aria-label="Keep what you have started?"
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Save draft">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="m5 12 5 5L20 7" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Save draft</strong><span>Keep your work for later</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Discard draft">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M6 6l12 12M18 6 6 18" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Discard draft</strong><span>Close without saving</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Continue editing">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M9 14 4 9l5-5" />
                  <path d="M4 9h11a5 5 0 0 1 0 10h-3" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Continue editing</strong><span>Return to your page</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">
            Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
          </p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Unsaved launch note',
        description: 'Choose whether to keep your draft, discard it or continue editing.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        dismissible: false,
        closeButton: false,
        showHandle: false,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">UNSAVED DRAFT</p>
          <h3>Keep what you have started?</h3>

          <div class="demo-scene">
            <div class="demo-scene-row">
              <p>
                Launch note: The new collection goes live on Friday. Add the product screenshots
                before the review.
              </p>
            </div>
          </div>
          <div
            class="demo-menu"
            role="group"
            aria-label="Keep what you have started?"
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Save draft">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="m5 12 5 5L20 7" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Save draft</strong><span>Keep your work for later</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Discard draft">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M6 6l12 12M18 6 6 18" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Discard draft</strong><span>Close without saving</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Continue editing">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M9 14 4 9l5-5" />
                  <path d="M4 9h11a5 5 0 0 1 0 10h-3" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Continue editing</strong><span>Return to your page</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">
            Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
          </p>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Unsaved launch note',
  description: 'Choose whether to keep your draft, discard it or continue editing.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  dismissible: false,
  closeButton: false,
  showHandle: false,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">UNSAVED DRAFT</p>
          <h3>Keep what you have started?</h3>

          <div class="demo-scene">
            <div class="demo-scene-row">
              <p>
                Launch note: The new collection goes live on Friday. Add the product screenshots
                before the review.
              </p>
            </div>
          </div>
          <div
            class="demo-menu"
            role="group"
            aria-label="Keep what you have started?"
            data-drawer-no-drag
          >
            <button type="button" class="demo-menu-item" data-demo-choice="Save draft">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="m5 12 5 5L20 7" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Save draft</strong><span>Keep your work for later</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Discard draft">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M6 6l12 12M18 6 6 18" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Discard draft</strong><span>Close without saving</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg></button
            ><button type="button" class="demo-menu-item" data-demo-choice="Continue editing">
              <span class="demo-menu-icon" aria-hidden="true"
                ><svg
                  aria-hidden="true"
                  focusable="false"
                  width="1.25rem"
                  height="1.25rem"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  stroke-width="1.75"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                >
                  <path d="M9 14 4 9l5-5" />
                  <path d="M4 9h11a5 5 0 0 1 0 10h-3" /></svg></span
              ><span class="demo-menu-copy"
                ><strong>Continue editing</strong><span>Return to your page</span></span
              ><svg
                aria-hidden="true"
                focusable="false"
                width="1em"
                height="1em"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="1.75"
                stroke-linecap="round"
                stroke-linejoin="round"
              >
                <path d="M5 12h14M13 5l7 7-7 7" />
              </svg>
            </button>
          </div>
          <p class="demo-hint">
            Your launch note has unsaved changes. Keep the draft, discard it, or return to editing.
          </p>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Unsaved launch note',
        description: 'Choose whether to keep your draft, discard it or continue editing.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        dismissible: false,
        closeButton: false,
        showHandle: false,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
16 / bottom

A guided flow, one step at a time

A guided flow, one step at a timeLive · @samline/drawer

CUSTOM TOTE / 3 STEPS

Choose. Personalize. Review.

Keep selections while moving forward and back inside one owned drawer.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

Back keeps your choices within this open panel. Confirmation reports a local sample selection; closing and reopening starts a fresh form.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker" data-flow-progress aria-live="polite">Step 1 / 3</p>
          <section data-flow-step="0">
            <h3 tabindex="-1">Choose the finish</h3>
            <label for="canvas-finish">Canvas finish</label
            ><select id="canvas-finish" data-flow-finish>
              <option>Natural canvas</option>
              <option>Midnight canvas</option></select
            ><button type="button" data-flow-next>Continue</button>
          </section>
          <section data-flow-step="1" hidden>
            <h3 tabindex="-1">Make it yours</h3>
            <label
              >Initials (optional)<input data-flow-initials maxlength="3" placeholder="e.g. AM"
            /></label>
            <p class="demo-hint">Up to three characters, printed on the inside pocket.</p>
            <div class="demo-actions">
              <button type="button" data-flow-back>Back</button
              ><button type="button" data-flow-next>Continue</button>
            </div>
          </section>
          <section data-flow-step="2" hidden>
            <h3 tabindex="-1">Review your tote</h3>
            <p>Everyday tote · $32 · Your selection</p>
            <p data-flow-summary></p>
            <div class="demo-actions">
              <button type="button" data-flow-back>Back</button
              ><button type="button" data-flow-confirm>Confirm sample selection</button>
            </div>
          </section>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer [data-flow-step][hidden] {
  display: none;
}
.demo-drawer [data-flow-step]:not([hidden]) {
  display: grid;
  gap: 1rem;
  margin-top: 0;
}
.demo-drawer [data-flow-step] > :is(h3, p) {
  margin: 0;
}
.demo-drawer [data-flow-step] > button {
  justify-self: start;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Make it your everyday tote',
  description: 'Choose a finish, review your selection and go back without losing it.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    let step = 0
    const steps = [...body.querySelectorAll('[data-flow-step]')]
    const finish = body.querySelector('[data-flow-finish]')
    const initials = body.querySelector('[data-flow-initials]')
    const selection = () => finish.value + ' · ' + (initials.value.trim() || 'No initials')
    const show = next => {
      step = next
      steps.forEach((section, index) => {
        section.hidden = index !== step
      })
      body.querySelector('[data-flow-progress]').textContent = 'Step' + ' ' + (step + 1) + ' / 3'
      body.querySelector('[data-flow-summary]').textContent = selection()
      steps[step].querySelector('h3').focus()
    }
    body
      .querySelectorAll('button[data-flow-next]')
      .forEach(button =>
        button.addEventListener('click', () => show(step + 1), { signal: lifecycle.signal })
      )
    body
      .querySelectorAll('button[data-flow-back]')
      .forEach(button =>
        button.addEventListener('click', () => show(step - 1), { signal: lifecycle.signal })
      )
    body.querySelector('button[data-flow-confirm]').addEventListener(
      'click',
      () => {
        document.getElementById('demo-result').textContent = 'Configured:' + ' ' + selection()
        drawer.setOpen(false)
      },
      { signal: lifecycle.signal }
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer [data-flow-step][hidden] {
        display: none;
      }
      .demo-drawer [data-flow-step]:not([hidden]) {
        display: grid;
        gap: 1rem;
        margin-top: 0;
      }
      .demo-drawer [data-flow-step] > :is(h3, p) {
        margin: 0;
      }
      .demo-drawer [data-flow-step] > button {
        justify-self: start;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker" data-flow-progress aria-live="polite">Step 1 / 3</p>
          <section data-flow-step="0">
            <h3 tabindex="-1">Choose the finish</h3>
            <label for="canvas-finish">Canvas finish</label
            ><select id="canvas-finish" data-flow-finish>
              <option>Natural canvas</option>
              <option>Midnight canvas</option></select
            ><button type="button" data-flow-next>Continue</button>
          </section>
          <section data-flow-step="1" hidden>
            <h3 tabindex="-1">Make it yours</h3>
            <label
              >Initials (optional)<input data-flow-initials maxlength="3" placeholder="e.g. AM"
            /></label>
            <p class="demo-hint">Up to three characters, printed on the inside pocket.</p>
            <div class="demo-actions">
              <button type="button" data-flow-back>Back</button
              ><button type="button" data-flow-next>Continue</button>
            </div>
          </section>
          <section data-flow-step="2" hidden>
            <h3 tabindex="-1">Review your tote</h3>
            <p>Everyday tote · $32 · Your selection</p>
            <p data-flow-summary></p>
            <div class="demo-actions">
              <button type="button" data-flow-back>Back</button
              ><button type="button" data-flow-confirm>Confirm sample selection</button>
            </div>
          </section>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Make it your everyday tote',
        description: 'Choose a finish, review your selection and go back without losing it.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          let step = 0
          const steps = [...body.querySelectorAll('[data-flow-step]')]
          const finish = body.querySelector('[data-flow-finish]')
          const initials = body.querySelector('[data-flow-initials]')
          const selection = () => finish.value + ' · ' + (initials.value.trim() || 'No initials')
          const show = next => {
            step = next
            steps.forEach((section, index) => {
              section.hidden = index !== step
            })
            body.querySelector('[data-flow-progress]').textContent =
              'Step' + ' ' + (step + 1) + ' / 3'
            body.querySelector('[data-flow-summary]').textContent = selection()
            steps[step].querySelector('h3').focus()
          }
          body
            .querySelectorAll('button[data-flow-next]')
            .forEach(button =>
              button.addEventListener('click', () => show(step + 1), { signal: lifecycle.signal })
            )
          body
            .querySelectorAll('button[data-flow-back]')
            .forEach(button =>
              button.addEventListener('click', () => show(step - 1), { signal: lifecycle.signal })
            )
          body.querySelector('button[data-flow-confirm]').addEventListener(
            'click',
            () => {
              document.getElementById('demo-result').textContent = 'Configured:' + ' ' + selection()
              drawer.setOpen(false)
            },
            { signal: lifecycle.signal }
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker" data-flow-progress aria-live="polite">Step 1 / 3</p>
          <section data-flow-step="0">
            <h3 tabindex="-1">Choose the finish</h3>
            <label for="canvas-finish">Canvas finish</label
            ><select id="canvas-finish" data-flow-finish>
              <option>Natural canvas</option>
              <option>Midnight canvas</option></select
            ><button type="button" data-flow-next>Continue</button>
          </section>
          <section data-flow-step="1" hidden>
            <h3 tabindex="-1">Make it yours</h3>
            <label
              >Initials (optional)<input data-flow-initials maxlength="3" placeholder="e.g. AM"
            /></label>
            <p class="demo-hint">Up to three characters, printed on the inside pocket.</p>
            <div class="demo-actions">
              <button type="button" data-flow-back>Back</button
              ><button type="button" data-flow-next>Continue</button>
            </div>
          </section>
          <section data-flow-step="2" hidden>
            <h3 tabindex="-1">Review your tote</h3>
            <p>Everyday tote · $32 · Your selection</p>
            <p data-flow-summary></p>
            <div class="demo-actions">
              <button type="button" data-flow-back>Back</button
              ><button type="button" data-flow-confirm>Confirm sample selection</button>
            </div>
          </section>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer [data-flow-step][hidden] {
  display: none;
}
.demo-drawer [data-flow-step]:not([hidden]) {
  display: grid;
  gap: 1rem;
  margin-top: 0;
}
.demo-drawer [data-flow-step] > :is(h3, p) {
  margin: 0;
}
.demo-drawer [data-flow-step] > button {
  justify-self: start;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'Make it your everyday tote',
  description: 'Choose a finish, review your selection and go back without losing it.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    let step = 0
    const steps = [...body.querySelectorAll('[data-flow-step]')]
    const finish = body.querySelector('[data-flow-finish]')
    const initials = body.querySelector('[data-flow-initials]')
    const selection = () => finish.value + ' · ' + (initials.value.trim() || 'No initials')
    const show = next => {
      step = next
      steps.forEach((section, index) => {
        section.hidden = index !== step
      })
      body.querySelector('[data-flow-progress]').textContent = 'Step' + ' ' + (step + 1) + ' / 3'
      body.querySelector('[data-flow-summary]').textContent = selection()
      steps[step].querySelector('h3').focus()
    }
    body
      .querySelectorAll('button[data-flow-next]')
      .forEach(button =>
        button.addEventListener('click', () => show(step + 1), { signal: lifecycle.signal })
      )
    body
      .querySelectorAll('button[data-flow-back]')
      .forEach(button =>
        button.addEventListener('click', () => show(step - 1), { signal: lifecycle.signal })
      )
    body.querySelector('button[data-flow-confirm]').addEventListener(
      'click',
      () => {
        document.getElementById('demo-result').textContent = 'Configured:' + ' ' + selection()
        drawer.setOpen(false)
      },
      { signal: lifecycle.signal }
    )

    return body
  },
  contentClassName: 'demo-drawer',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer [data-flow-step][hidden] {
        display: none;
      }
      .demo-drawer [data-flow-step]:not([hidden]) {
        display: grid;
        gap: 1rem;
        margin-top: 0;
      }
      .demo-drawer [data-flow-step] > :is(h3, p) {
        margin: 0;
      }
      .demo-drawer [data-flow-step] > button {
        justify-self: start;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker" data-flow-progress aria-live="polite">Step 1 / 3</p>
          <section data-flow-step="0">
            <h3 tabindex="-1">Choose the finish</h3>
            <label for="canvas-finish">Canvas finish</label
            ><select id="canvas-finish" data-flow-finish>
              <option>Natural canvas</option>
              <option>Midnight canvas</option></select
            ><button type="button" data-flow-next>Continue</button>
          </section>
          <section data-flow-step="1" hidden>
            <h3 tabindex="-1">Make it yours</h3>
            <label
              >Initials (optional)<input data-flow-initials maxlength="3" placeholder="e.g. AM"
            /></label>
            <p class="demo-hint">Up to three characters, printed on the inside pocket.</p>
            <div class="demo-actions">
              <button type="button" data-flow-back>Back</button
              ><button type="button" data-flow-next>Continue</button>
            </div>
          </section>
          <section data-flow-step="2" hidden>
            <h3 tabindex="-1">Review your tote</h3>
            <p>Everyday tote · $32 · Your selection</p>
            <p data-flow-summary></p>
            <div class="demo-actions">
              <button type="button" data-flow-back>Back</button
              ><button type="button" data-flow-confirm>Confirm sample selection</button>
            </div>
          </section>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'Make it your everyday tote',
        description: 'Choose a finish, review your selection and go back without losing it.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          let step = 0
          const steps = [...body.querySelectorAll('[data-flow-step]')]
          const finish = body.querySelector('[data-flow-finish]')
          const initials = body.querySelector('[data-flow-initials]')
          const selection = () => finish.value + ' · ' + (initials.value.trim() || 'No initials')
          const show = next => {
            step = next
            steps.forEach((section, index) => {
              section.hidden = index !== step
            })
            body.querySelector('[data-flow-progress]').textContent =
              'Step' + ' ' + (step + 1) + ' / 3'
            body.querySelector('[data-flow-summary]').textContent = selection()
            steps[step].querySelector('h3').focus()
          }
          body
            .querySelectorAll('button[data-flow-next]')
            .forEach(button =>
              button.addEventListener('click', () => show(step + 1), { signal: lifecycle.signal })
            )
          body
            .querySelectorAll('button[data-flow-back]')
            .forEach(button =>
              button.addEventListener('click', () => show(step - 1), { signal: lifecycle.signal })
            )
          body.querySelector('button[data-flow-confirm]').addEventListener(
            'click',
            () => {
              document.getElementById('demo-result').textContent = 'Configured:' + ' ' + selection()
              drawer.setOpen(false)
            },
            { signal: lifecycle.signal }
          )

          return body
        },
        contentClassName: 'demo-drawer',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
17 / left

Two panels, independent lives

Two panels, independent livesLive · @samline/drawer

PROJECT WORKSPACE

Notes here. Activity there.

Open notes and activity together. Neither is the parent; closing one leaves the other open.

Closed

These non-modal panels have separate controllers and close actions. On small screens they occupy separate upper and lower regions.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>
      <button type="button" id="open-activity" aria-haspopup="dialog" aria-expanded="false">
        Open activity
      </button>
      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p>Write a review note, then open activity. You can close either panel separately.</p>
          <label data-drawer-no-drag
            >Project review note<textarea
              placeholder="What should the team review next?"
            ></textarea></label
          ><button type="button" data-open-companion aria-haspopup="dialog">Open activity</button
          ><template data-companion-content
            ><div class="demo-body">
              <section>
                <h3>Alex added the product shots</h3>
                <p>Today · 09:20</p>
              </section>
              <section>
                <h3>Maya updated the launch checklist</h3>
                <p>Today · 09:05</p>
              </section>
            </div></template
          >
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer.demo-floating {
  isolation: isolate;
  background: transparent;
}
.demo-drawer.demo-floating::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #faf9fc;
  z-index: -1;
  pointer-events: none;
}

.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
  --initial-transform: 100dvw;
  width: min(27rem, 46vw);
  max-height: calc(100dvh - 2rem);
  top: 1rem;
  bottom: 1rem;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
}
.demo-drawer.demo-independent-notes {
  right: auto;
  left: 1rem;
}
.demo-drawer.demo-independent-activity {
  left: auto;
  right: 1rem;
}
@media (width < 48rem) {
  .demo-drawer.demo-independent-notes,
  .demo-drawer.demo-independent-activity {
    width: calc(100% - 2rem);
    height: 44dvh;
    max-height: 44dvh;
  }
  .demo-drawer.demo-independent-notes {
    top: 1rem;
    bottom: auto;
  }
  .demo-drawer.demo-independent-activity {
    top: auto;
    bottom: 1rem;
  }
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

let companion
const activityTrigger = document.getElementById('open-activity')
const openActivity = () => {
  companion ??= window.Drawer.createDrawer({
    id: 'example-activity',
    direction: 'right',
    title: 'Project activity',
    description:
      'Recent updates from your product team. Keep this log open beside your review notes.',
    modal: false,
    overlay: false,
    autoFocus: false,
    content: () =>
      template.content
        .querySelector('[data-companion-content]')
        .content.firstElementChild.cloneNode(true),
    contentClassName: 'demo-drawer demo-floating demo-independent-activity',
    showHandle: false,
    closeButton: { ariaLabel: 'Close activity' },
    onOpenChange: open => activityTrigger.setAttribute('aria-expanded', String(open)),
  })
  companion.setOpen(true)
}
activityTrigger.addEventListener('click', openActivity, { signal: lifecycle.signal })
const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'left',
  title: 'Project notes',
  description: 'Keep your review notes open beside an independent activity panel.',
  autoFocus: false,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    body
      .querySelector('button[data-open-companion]')
      .addEventListener('click', openActivity, { signal: lifecycle.signal })

    return body
  },
  contentClassName: 'demo-drawer demo-floating demo-independent-notes',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  modal: false,
  overlay: false,
  showHandle: false,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
    companion?.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer.demo-floating {
        isolation: isolate;
        background: transparent;
      }
      .demo-drawer.demo-floating::before {
        content: '';
        position: absolute;
        inset: 0;
        border-radius: inherit;
        background: #faf9fc;
        z-index: -1;
        pointer-events: none;
      }

      .demo-drawer.demo-independent-notes,
      .demo-drawer.demo-independent-activity {
        --initial-transform: 100dvw;
        width: min(27rem, 46vw);
        max-height: calc(100dvh - 2rem);
        top: 1rem;
        bottom: 1rem;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
      }
      .demo-drawer.demo-independent-notes {
        right: auto;
        left: 1rem;
      }
      .demo-drawer.demo-independent-activity {
        left: auto;
        right: 1rem;
      }
      @media (width < 48rem) {
        .demo-drawer.demo-independent-notes,
        .demo-drawer.demo-independent-activity {
          width: calc(100% - 2rem);
          height: 44dvh;
          max-height: 44dvh;
        }
        .demo-drawer.demo-independent-notes {
          top: 1rem;
          bottom: auto;
        }
        .demo-drawer.demo-independent-activity {
          top: auto;
          bottom: 1rem;
        }
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>
      <button type="button" id="open-activity" aria-haspopup="dialog" aria-expanded="false">
        Open activity
      </button>
      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p>Write a review note, then open activity. You can close either panel separately.</p>
          <label data-drawer-no-drag
            >Project review note<textarea
              placeholder="What should the team review next?"
            ></textarea></label
          ><button type="button" data-open-companion aria-haspopup="dialog">Open activity</button
          ><template data-companion-content
            ><div class="demo-body">
              <section>
                <h3>Alex added the product shots</h3>
                <p>Today · 09:20</p>
              </section>
              <section>
                <h3>Maya updated the launch checklist</h3>
                <p>Today · 09:05</p>
              </section>
            </div></template
          >
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      let companion
      const activityTrigger = document.getElementById('open-activity')
      const openActivity = () => {
        companion ??= window.Drawer.createDrawer({
          id: 'example-activity',
          direction: 'right',
          title: 'Project activity',
          description:
            'Recent updates from your product team. Keep this log open beside your review notes.',
          modal: false,
          overlay: false,
          autoFocus: false,
          content: () =>
            template.content
              .querySelector('[data-companion-content]')
              .content.firstElementChild.cloneNode(true),
          contentClassName: 'demo-drawer demo-floating demo-independent-activity',
          showHandle: false,
          closeButton: { ariaLabel: 'Close activity' },
          onOpenChange: open => activityTrigger.setAttribute('aria-expanded', String(open)),
        })
        companion.setOpen(true)
      }
      activityTrigger.addEventListener('click', openActivity, { signal: lifecycle.signal })
      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'left',
        title: 'Project notes',
        description: 'Keep your review notes open beside an independent activity panel.',
        autoFocus: false,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          body
            .querySelector('button[data-open-companion]')
            .addEventListener('click', openActivity, { signal: lifecycle.signal })

          return body
        },
        contentClassName: 'demo-drawer demo-floating demo-independent-notes',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        modal: false,
        overlay: false,
        showHandle: false,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
          companion?.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>
      <button type="button" id="open-activity" aria-haspopup="dialog" aria-expanded="false">
        Open activity
      </button>
      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p>Write a review note, then open activity. You can close either panel separately.</p>
          <label data-drawer-no-drag
            >Project review note<textarea
              placeholder="What should the team review next?"
            ></textarea></label
          ><button type="button" data-open-companion aria-haspopup="dialog">Open activity</button
          ><template data-companion-content
            ><div class="demo-body">
              <section>
                <h3>Alex added the product shots</h3>
                <p>Today · 09:20</p>
              </section>
              <section>
                <h3>Maya updated the launch checklist</h3>
                <p>Today · 09:05</p>
              </section>
            </div></template
          >
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(28rem, 90vw);
  max-height: 100dvh;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer.demo-floating {
  isolation: isolate;
  background: transparent;
}
.demo-drawer.demo-floating::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #faf9fc;
  z-index: -1;
  pointer-events: none;
}

.demo-drawer.demo-independent-notes,
.demo-drawer.demo-independent-activity {
  --initial-transform: 100dvw;
  width: min(27rem, 46vw);
  max-height: calc(100dvh - 2rem);
  top: 1rem;
  bottom: 1rem;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
}
.demo-drawer.demo-independent-notes {
  right: auto;
  left: 1rem;
}
.demo-drawer.demo-independent-activity {
  left: auto;
  right: 1rem;
}
@media (width < 48rem) {
  .demo-drawer.demo-independent-notes,
  .demo-drawer.demo-independent-activity {
    width: calc(100% - 2rem);
    height: 44dvh;
    max-height: 44dvh;
  }
  .demo-drawer.demo-independent-notes {
    top: 1rem;
    bottom: auto;
  }
  .demo-drawer.demo-independent-activity {
    top: auto;
    bottom: 1rem;
  }
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

let companion
const activityTrigger = document.getElementById('open-activity')
const openActivity = () => {
  companion ??= createDrawer({
    id: 'example-activity',
    direction: 'right',
    title: 'Project activity',
    description:
      'Recent updates from your product team. Keep this log open beside your review notes.',
    modal: false,
    overlay: false,
    autoFocus: false,
    content: () =>
      template.content
        .querySelector('[data-companion-content]')
        .content.firstElementChild.cloneNode(true),
    contentClassName: 'demo-drawer demo-floating demo-independent-activity',
    showHandle: false,
    closeButton: { ariaLabel: 'Close activity' },
    onOpenChange: open => activityTrigger.setAttribute('aria-expanded', String(open)),
  })
  companion.setOpen(true)
}
activityTrigger.addEventListener('click', openActivity, { signal: lifecycle.signal })
const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'left',
  title: 'Project notes',
  description: 'Keep your review notes open beside an independent activity panel.',
  autoFocus: false,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    body
      .querySelector('button[data-open-companion]')
      .addEventListener('click', openActivity, { signal: lifecycle.signal })

    return body
  },
  contentClassName: 'demo-drawer demo-floating demo-independent-notes',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  modal: false,
  overlay: false,
  showHandle: false,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
    companion?.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(28rem, 90vw);
        max-height: 100dvh;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer.demo-floating {
        isolation: isolate;
        background: transparent;
      }
      .demo-drawer.demo-floating::before {
        content: '';
        position: absolute;
        inset: 0;
        border-radius: inherit;
        background: #faf9fc;
        z-index: -1;
        pointer-events: none;
      }

      .demo-drawer.demo-independent-notes,
      .demo-drawer.demo-independent-activity {
        --initial-transform: 100dvw;
        width: min(27rem, 46vw);
        max-height: calc(100dvh - 2rem);
        top: 1rem;
        bottom: 1rem;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
      }
      .demo-drawer.demo-independent-notes {
        right: auto;
        left: 1rem;
      }
      .demo-drawer.demo-independent-activity {
        left: auto;
        right: 1rem;
      }
      @media (width < 48rem) {
        .demo-drawer.demo-independent-notes,
        .demo-drawer.demo-independent-activity {
          width: calc(100% - 2rem);
          height: 44dvh;
          max-height: 44dvh;
        }
        .demo-drawer.demo-independent-notes {
          top: 1rem;
          bottom: auto;
        }
        .demo-drawer.demo-independent-activity {
          top: auto;
          bottom: 1rem;
        }
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>
      <button type="button" id="open-activity" aria-haspopup="dialog" aria-expanded="false">
        Open activity
      </button>
      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p>Write a review note, then open activity. You can close either panel separately.</p>
          <label data-drawer-no-drag
            >Project review note<textarea
              placeholder="What should the team review next?"
            ></textarea></label
          ><button type="button" data-open-companion aria-haspopup="dialog">Open activity</button
          ><template data-companion-content
            ><div class="demo-body">
              <section>
                <h3>Alex added the product shots</h3>
                <p>Today · 09:20</p>
              </section>
              <section>
                <h3>Maya updated the launch checklist</h3>
                <p>Today · 09:05</p>
              </section>
            </div></template
          >
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      let companion
      const activityTrigger = document.getElementById('open-activity')
      const openActivity = () => {
        companion ??= createDrawer({
          id: 'example-activity',
          direction: 'right',
          title: 'Project activity',
          description:
            'Recent updates from your product team. Keep this log open beside your review notes.',
          modal: false,
          overlay: false,
          autoFocus: false,
          content: () =>
            template.content
              .querySelector('[data-companion-content]')
              .content.firstElementChild.cloneNode(true),
          contentClassName: 'demo-drawer demo-floating demo-independent-activity',
          showHandle: false,
          closeButton: { ariaLabel: 'Close activity' },
          onOpenChange: open => activityTrigger.setAttribute('aria-expanded', String(open)),
        })
        companion.setOpen(true)
      }
      activityTrigger.addEventListener('click', openActivity, { signal: lifecycle.signal })
      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'left',
        title: 'Project notes',
        description: 'Keep your review notes open beside an independent activity panel.',
        autoFocus: false,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          body
            .querySelector('button[data-open-companion]')
            .addEventListener('click', openActivity, { signal: lifecycle.signal })

          return body
        },
        contentClassName: 'demo-drawer demo-floating demo-independent-notes',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        modal: false,
        overlay: false,
        showHandle: false,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
          companion?.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>
18 / bottom

The same Drawer, a different design

The same Drawer, a different designLive · @samline/drawer

STUDIO / AN INVITATION

Your design sets the shape.

A floating invitation card: custom width, all-around corners and a soft accent gradient. Your CSS sets the design.

Closed

Clear the previous result when you reopen. A completed choice stays visible after closing so you can read it. Uncheck to keep that result between attempts; panel inputs still recreate normally. A playground helper for repeat trials; it is not part of Drawer or the copied integration code.

This is a local sample invitation. The floating shape and gradient are application CSS, not a built-in Drawer theme.

Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">STUDIO / AN INVITATION</p>
          <h3>Good work starts together.</h3>
          <p>
            Join the product team to share projects, review designs and keep decisions in one place.
          </p>
          <p class="demo-hint">Product team · 6 teammates · Member access</p>
          <button type="button" data-demo-choice="Accept sample invitation" data-drawer-no-drag>
            Accept sample invitation
          </button>
          <p class="demo-hint">
            Sample invitation only. Accepting does not create or change a real account.
          </p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer.demo-floating {
  isolation: isolate;
  background: transparent;
}
.demo-drawer.demo-floating::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #faf9fc;
  z-index: -1;
  pointer-events: none;
}

/* No runtime changes: geometry, corners and gradient belong to your CSS. */
.demo-drawer.demo-invitation {
  --initial-transform: 100dvh;
  inset: 1rem;
  margin: auto;
  width: min(34rem, calc(100% - 2rem));
  height: fit-content;
  min-height: 0;
  max-height: calc(100dvh - 2rem);
  border: 0.0625rem solid #952779;
  border-radius: 2rem 0.5rem 2rem 0.5rem;
}
.demo-drawer.demo-invitation::before {
  background: linear-gradient(155deg, #faf9fc 50%, #f3dfed);
}
.demo-drawer.demo-invitation button[data-drawer-close] {
  border-radius: 100rem;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = window.Drawer.createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'A place on the team',
  description: 'Alex invited you to the Studio workspace.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer demo-floating demo-invitation',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  showHandle: false,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/style.css"
    />
    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer.demo-floating {
        isolation: isolate;
        background: transparent;
      }
      .demo-drawer.demo-floating::before {
        content: '';
        position: absolute;
        inset: 0;
        border-radius: inherit;
        background: #faf9fc;
        z-index: -1;
        pointer-events: none;
      }

      /* No runtime changes: geometry, corners and gradient belong to your CSS. */
      .demo-drawer.demo-invitation {
        --initial-transform: 100dvh;
        inset: 1rem;
        margin: auto;
        width: min(34rem, calc(100% - 2rem));
        height: fit-content;
        min-height: 0;
        max-height: calc(100dvh - 2rem);
        border: 0.0625rem solid #952779;
        border-radius: 2rem 0.5rem 2rem 0.5rem;
      }
      .demo-drawer.demo-invitation::before {
        background: linear-gradient(155deg, #faf9fc 50%, #f3dfed);
      }
      .demo-drawer.demo-invitation button[data-drawer-close] {
        border-radius: 100rem;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">STUDIO / AN INVITATION</p>
          <h3>Good work starts together.</h3>
          <p>
            Join the product team to share projects, review designs and keep decisions in one place.
          </p>
          <p class="demo-hint">Product team · 6 teammates · Member access</p>
          <button type="button" data-demo-choice="Accept sample invitation" data-drawer-no-drag>
            Accept sample invitation
          </button>
          <p class="demo-hint">
            Sample invitation only. Accepting does not create or change a real account.
          </p>
        </div>
      </template>
    </main>

    <script src="https://cdn.jsdelivr.net/npm/@samline/drawer@6.0.1/dist/browser/drawer.global.js"></script>
    <script>
      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = window.Drawer.createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'A place on the team',
        description: 'Alex invited you to the Studio workspace.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer demo-floating demo-invitation',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        showHandle: false,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">STUDIO / AN INVITATION</p>
          <h3>Good work starts together.</h3>
          <p>
            Join the product team to share projects, review designs and keep decisions in one place.
          </p>
          <p class="demo-hint">Product team · 6 teammates · Member access</p>
          <button type="button" data-demo-choice="Accept sample invitation" data-drawer-no-drag>
            Accept sample invitation
          </button>
          <p class="demo-hint">
            Sample invitation only. Accepting does not create or change a real account.
          </p>
        </div>
      </template>
    </main>

    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
body {
  margin: 0;
  padding: 2rem;
  font:
    1rem/1.6 system-ui,
    sans-serif;
}
button {
  font: inherit;
  cursor: pointer;
  padding: 0.75rem 1rem;
}
.demo-overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  z-index: 101;
}
.demo-drawer {
  display: flex;
  flex-direction: column;
  position: fixed;
  box-sizing: border-box;
  background: #faf9fc;
  color: #24212b;
  z-index: 101;
  padding: 2rem;
  max-height: 90dvh;
  outline: none;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 1.5rem 1.5rem 0 0;
  min-height: 18rem;
}

.demo-drawer [data-drawer-title] {
  margin: 1rem 0;
  font-size: 1.75rem;
  line-height: 1.15;
  padding-right: 3rem;
}
.demo-drawer [data-drawer-description] {
  margin: 0 0 1.5rem;
}
.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.demo-body {
  display: grid;
  gap: 1rem;
  width: min(100%, 52rem);
  margin-inline: auto;
}
.demo-body > button,
.demo-body form > button {
  justify-self: start;
  width: fit-content;
  max-width: 100%;
}
.demo-scene {
  display: grid;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  background: #f3edf3;
}
.demo-scene-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 1rem;
}
.demo-scene-row + .demo-scene-row {
  border-top: 0.0625rem solid #d9cbd5;
}
.demo-scene-row p {
  color: #625361;
  font-size: 0.875rem;
}

.demo-menu {
  display: grid;
  gap: 0.75rem;
}
.demo-menu-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  border: 0.0625rem solid #d9cbd5;
  border-radius: 0.875rem;
  color: inherit;
  background: #f3edf3;
}
.demo-menu-item[hidden] {
  display: none;
}
.demo-menu-copy {
  display: grid;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}
.demo-menu-copy > span,
.demo-hint {
  font-size: 0.875rem;
  color: #625361;
}
.demo-menu-icon {
  display: grid;
  place-items: center;
  flex: 0 0 2.5rem;
  height: 2.5rem;
  color: #a32379;
}
.demo-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: #a32379;
}
.demo-body h3,
.demo-body p {
  margin: 0;
}
.demo-body:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: -0.125rem;
}
.demo-body ul {
  margin: 0;
  padding-left: 1.25rem;
}
.demo-body li + li {
  margin-top: 0.5rem;
}
.demo-drawer [data-drawer-close] {
  position: sticky;
  order: -1;
  flex: 0 0 auto;
  top: 0;
  display: block;
  margin-left: auto;
  z-index: 1;
  background: #faf9fc;
}
.demo-body label,
.demo-body form {
  display: grid;
  gap: 0.75rem;
}
.demo-body input,
.demo-body select,
.demo-body textarea {
  max-width: 100%;
  box-sizing: border-box;
  font: inherit;
  padding: 0.75rem;
}
.demo-body section + section {
  margin-top: 1.5rem;
}
#demo-result {
  display: block;
}
.demo-drawer [data-drawer-handle] {
  order: -2;
  flex-shrink: 0;
  margin-inline: auto;
}
.demo-drawer [data-drawer-body] {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.demo-drawer [data-drawer-title],
.demo-drawer [data-drawer-description] {
  flex-shrink: 0;
  width: min(100%, 52rem);
  margin-inline: auto;
  box-sizing: border-box;
}

.demo-drawer.demo-floating {
  isolation: isolate;
  background: transparent;
}
.demo-drawer.demo-floating::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #faf9fc;
  z-index: -1;
  pointer-events: none;
}

/* No runtime changes: geometry, corners and gradient belong to your CSS. */
.demo-drawer.demo-invitation {
  --initial-transform: 100dvh;
  inset: 1rem;
  margin: auto;
  width: min(34rem, calc(100% - 2rem));
  height: fit-content;
  min-height: 0;
  max-height: calc(100dvh - 2rem);
  border: 0.0625rem solid #952779;
  border-radius: 2rem 0.5rem 2rem 0.5rem;
}
.demo-drawer.demo-invitation::before {
  background: linear-gradient(155deg, #faf9fc 50%, #f3dfed);
}
.demo-drawer.demo-invitation button[data-drawer-close] {
  border-radius: 100rem;
}

.demo-drawer:focus-visible,
button:focus-visible {
  outline: 0.125rem solid #a32379;
  outline-offset: 0.1875rem;
}

JavaScript

main.js
import { createDrawer } from '@samline/drawer'
import '@samline/drawer/style.css'
import './style.css'

const lifecycle = new AbortController()
const trigger = document.getElementById('open-drawer')
const template = document.getElementById('drawer-content')

const drawer = createDrawer({
  id: 'example',
  triggerElement: trigger,
  direction: 'bottom',
  title: 'A place on the team',
  description: 'Alex invited you to the Studio workspace.',
  autoFocus: true,
  content: () => {
    const body = template.content.firstElementChild.cloneNode(true)

    const choices = [...body.querySelectorAll('button[data-demo-choice]')]
    choices.forEach(button =>
      button.addEventListener(
        'click',
        () => {
          document.getElementById('demo-result').textContent =
            'Selected:' + ' ' + button.dataset.demoChoice
          drawer.setOpen(false)
        },
        { signal: lifecycle.signal }
      )
    )

    return body
  },
  contentClassName: 'demo-drawer demo-floating demo-invitation',
  overlayClassName: 'demo-overlay',
  showHandle: true,
  closeButton: { ariaLabel: 'Close drawer' },
  onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
  showHandle: false,
})

window.addEventListener(
  'pagehide',
  event => {
    if (event.persisted) return
    lifecycle.abort()
    drawer.destroy()
  },
  { signal: lifecycle.signal }
)

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Drawer playground</title>

    <style>
      body {
        margin: 0;
        padding: 2rem;
        font:
          1rem/1.6 system-ui,
          sans-serif;
      }
      button {
        font: inherit;
        cursor: pointer;
        padding: 0.75rem 1rem;
      }
      .demo-overlay {
        position: fixed;
        inset: 0;
        background: rgb(0 0 0 / 45%);
        z-index: 101;
      }
      .demo-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        box-sizing: border-box;
        background: #faf9fc;
        color: #24212b;
        z-index: 101;
        padding: 2rem;
        max-height: 90dvh;
        outline: none;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 1.5rem 1.5rem 0 0;
        min-height: 18rem;
      }

      .demo-drawer [data-drawer-title] {
        margin: 1rem 0;
        font-size: 1.75rem;
        line-height: 1.15;
        padding-right: 3rem;
      }
      .demo-drawer [data-drawer-description] {
        margin: 0 0 1.5rem;
      }
      .demo-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
      }
      .demo-body {
        display: grid;
        gap: 1rem;
        width: min(100%, 52rem);
        margin-inline: auto;
      }
      .demo-body > button,
      .demo-body form > button {
        justify-self: start;
        width: fit-content;
        max-width: 100%;
      }
      .demo-scene {
        display: grid;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        background: #f3edf3;
      }
      .demo-scene-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 1rem;
        padding: 1rem;
      }
      .demo-scene-row + .demo-scene-row {
        border-top: 0.0625rem solid #d9cbd5;
      }
      .demo-scene-row p {
        color: #625361;
        font-size: 0.875rem;
      }

      .demo-menu {
        display: grid;
        gap: 0.75rem;
      }
      .demo-menu-item {
        display: flex;
        align-items: center;
        gap: 1rem;
        width: 100%;
        text-align: left;
        border: 0.0625rem solid #d9cbd5;
        border-radius: 0.875rem;
        color: inherit;
        background: #f3edf3;
      }
      .demo-menu-item[hidden] {
        display: none;
      }
      .demo-menu-copy {
        display: grid;
        gap: 0.25rem;
        flex: 1;
        min-width: 0;
      }
      .demo-menu-copy > span,
      .demo-hint {
        font-size: 0.875rem;
        color: #625361;
      }
      .demo-menu-icon {
        display: grid;
        place-items: center;
        flex: 0 0 2.5rem;
        height: 2.5rem;
        color: #a32379;
      }
      .demo-kicker {
        font-size: 0.75rem;
        letter-spacing: 0.08em;
        color: #a32379;
      }
      .demo-body h3,
      .demo-body p {
        margin: 0;
      }
      .demo-body:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: -0.125rem;
      }
      .demo-body ul {
        margin: 0;
        padding-left: 1.25rem;
      }
      .demo-body li + li {
        margin-top: 0.5rem;
      }
      .demo-drawer [data-drawer-close] {
        position: sticky;
        order: -1;
        flex: 0 0 auto;
        top: 0;
        display: block;
        margin-left: auto;
        z-index: 1;
        background: #faf9fc;
      }
      .demo-body label,
      .demo-body form {
        display: grid;
        gap: 0.75rem;
      }
      .demo-body input,
      .demo-body select,
      .demo-body textarea {
        max-width: 100%;
        box-sizing: border-box;
        font: inherit;
        padding: 0.75rem;
      }
      .demo-body section + section {
        margin-top: 1.5rem;
      }
      #demo-result {
        display: block;
      }
      .demo-drawer [data-drawer-handle] {
        order: -2;
        flex-shrink: 0;
        margin-inline: auto;
      }
      .demo-drawer [data-drawer-body] {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
      }
      .demo-drawer [data-drawer-title],
      .demo-drawer [data-drawer-description] {
        flex-shrink: 0;
        width: min(100%, 52rem);
        margin-inline: auto;
        box-sizing: border-box;
      }

      .demo-drawer.demo-floating {
        isolation: isolate;
        background: transparent;
      }
      .demo-drawer.demo-floating::before {
        content: '';
        position: absolute;
        inset: 0;
        border-radius: inherit;
        background: #faf9fc;
        z-index: -1;
        pointer-events: none;
      }

      /* No runtime changes: geometry, corners and gradient belong to your CSS. */
      .demo-drawer.demo-invitation {
        --initial-transform: 100dvh;
        inset: 1rem;
        margin: auto;
        width: min(34rem, calc(100% - 2rem));
        height: fit-content;
        min-height: 0;
        max-height: calc(100dvh - 2rem);
        border: 0.0625rem solid #952779;
        border-radius: 2rem 0.5rem 2rem 0.5rem;
      }
      .demo-drawer.demo-invitation::before {
        background: linear-gradient(155deg, #faf9fc 50%, #f3dfed);
      }
      .demo-drawer.demo-invitation button[data-drawer-close] {
        border-radius: 100rem;
      }

      .demo-drawer:focus-visible,
      button:focus-visible {
        outline: 0.125rem solid #a32379;
        outline-offset: 0.1875rem;
      }
    </style>
  </head>

  <body>
    <main>
      <button type="button" id="open-drawer" aria-haspopup="dialog" aria-expanded="false">
        Open drawer
      </button>

      <output id="demo-result" aria-live="polite"></output>

      <template id="drawer-content">
        <div class="demo-body">
          <p class="demo-kicker">STUDIO / AN INVITATION</p>
          <h3>Good work starts together.</h3>
          <p>
            Join the product team to share projects, review designs and keep decisions in one place.
          </p>
          <p class="demo-hint">Product team · 6 teammates · Member access</p>
          <button type="button" data-demo-choice="Accept sample invitation" data-drawer-no-drag>
            Accept sample invitation
          </button>
          <p class="demo-hint">
            Sample invitation only. Accepting does not create or change a real account.
          </p>
        </div>
      </template>
    </main>

    <script type="module">
      import { createDrawer } from '@samline/drawer'
      import '@samline/drawer/style.css'

      const lifecycle = new AbortController()
      const trigger = document.getElementById('open-drawer')
      const template = document.getElementById('drawer-content')

      const drawer = createDrawer({
        id: 'example',
        triggerElement: trigger,
        direction: 'bottom',
        title: 'A place on the team',
        description: 'Alex invited you to the Studio workspace.',
        autoFocus: true,
        content: () => {
          const body = template.content.firstElementChild.cloneNode(true)

          const choices = [...body.querySelectorAll('button[data-demo-choice]')]
          choices.forEach(button =>
            button.addEventListener(
              'click',
              () => {
                document.getElementById('demo-result').textContent =
                  'Selected:' + ' ' + button.dataset.demoChoice
                drawer.setOpen(false)
              },
              { signal: lifecycle.signal }
            )
          )

          return body
        },
        contentClassName: 'demo-drawer demo-floating demo-invitation',
        overlayClassName: 'demo-overlay',
        showHandle: true,
        closeButton: { ariaLabel: 'Close drawer' },
        onOpenChange: open => trigger.setAttribute('aria-expanded', String(open)),
        showHandle: false,
      })

      window.addEventListener(
        'pagehide',
        event => {
          if (event.persisted) return
          lifecycle.abort()
          drawer.destroy()
        },
        { signal: lifecycle.signal }
      )
    </script>
  </body>
</html>

These examples show a few possibilities. The next ideas are yours: combine the package’s capabilities with your own content, design and interactions to create the experience your project needs.

Read the example guideBuilding with an AI agent? Download the Drawer skill
@samline/drawer

Drawers that move with you. Bottom sheets, side panels and nested flows with a typed, framework-free API.

v6.0.1·MIT

Explore

DocsInstallation guideWorking examples

Project

Drawer skill for AI agentsGitHub(opens in a new tab)Changelognpm(opens in a new tab)License(opens in a new tab)

© 2026 samline · Made for the open web.

Back to top