Skip to content

Drawer ​

A panel that slides up from the bottom, with a handle, for quick tasks on phones.

  • Version 1.0.0
  • Bootstrap 5.3+
  • Requires Bootstrap CSS + Bootstrap JS bundle
  • Source on GitHub

Installation ​

bash
npx bootcn add drawer
bash
pnpm dlx bootcn add drawer
bash
yarn dlx bootcn add drawer
bash
bunx --bun bootcn add drawer

The CLI also installs the design tokens and these components: button, input. It prints the <link> and <script> tags to add to your layout.

Usage ​

A drawer is a bottom offcanvas with a decorative handle and its content centred in a narrow column. It suits phones; on wide screens consider the Dialog or Sheet. The handle is visual only (no drag to close); use Cancel, Escape or the backdrop.

Accessibility ​

  • Bootstrap gives it role="dialog" and aria-modal while open, traps focus, closes on Escape and returns focus to the trigger.
  • The handle is hidden from screen readers.

Dependencies ​

  • Bootstrap 5.3+ CSS and the JS bundle.
  • themes/tokens/tokens.css.
  • The button component.
  • The input component.

Source ​

The exact files the CLI installs (drawer@1.0.0). View on GitHub · Report an issue

html
<button
  class="btn bootcn-button bootcn-button--outline"
  type="button"
  data-bs-toggle="offcanvas"
  data-bs-target="#bootcn-drawer"
  aria-controls="bootcn-drawer"
>
  Set a goal
</button>

<div
  class="offcanvas offcanvas-bottom bootcn-drawer"
  tabindex="-1"
  id="bootcn-drawer"
  aria-labelledby="bootcn-drawer-title"
>
  <div class="bootcn-drawer__handle" aria-hidden="true"></div>
  <div class="bootcn-drawer__inner">
    <div class="bootcn-drawer__header">
      <h2 class="offcanvas-title bootcn-drawer__title" id="bootcn-drawer-title">Daily goal</h2>
      <p class="bootcn-drawer__description">
        Choose how many minutes you want to practise each day.
      </p>
    </div>
    <div class="bootcn-drawer__body">
      <div class="bootcn-field">
        <label class="form-label bootcn-field__label" for="bootcn-drawer-minutes"
          >Minutes per day</label
        >
        <input
          class="form-control bootcn-input"
          type="number"
          id="bootcn-drawer-minutes"
          name="minutes"
          value="30"
          min="5"
          max="240"
          step="5"
          inputmode="numeric"
        />
      </div>
    </div>
    <div class="bootcn-drawer__footer">
      <button type="button" class="btn bootcn-button bootcn-button--default">Save goal</button>
      <button
        type="button"
        class="btn bootcn-button bootcn-button--outline"
        data-bs-dismiss="offcanvas"
      >
        Cancel
      </button>
    </div>
  </div>
</div>
css
.bootcn-drawer {
  --bs-offcanvas-height: auto;
  --bs-offcanvas-bg: var(--bootcn-background);
  --bs-offcanvas-color: var(--bootcn-foreground);
  --bs-offcanvas-border-color: var(--bootcn-border-color);

  max-height: 85vh;
  border-top-left-radius: var(--bootcn-radius-xl);
  border-top-right-radius: var(--bootcn-radius-xl);
  box-shadow: var(--bootcn-shadow-lg);
}

.bootcn-drawer__handle {
  flex: none;
  width: 6rem;
  height: 0.375rem;
  margin: 1rem auto 0;
  border-radius: 9999px;
  background-color: var(--bootcn-muted);
}

.bootcn-drawer__inner {
  width: 100%;
  max-width: 28rem;
  margin: 0 auto;
  overflow-y: auto;
  padding: 1rem 1rem 1.5rem;
}

.bootcn-drawer__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  text-align: center;
}

.bootcn-drawer__description {
  margin: 0.375rem 0 0;
  color: var(--bootcn-muted-foreground);
  font-size: 0.875rem;
  text-align: center;
}

.bootcn-drawer__body {
  padding: 1.5rem 0;
}

.bootcn-drawer__footer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

Released under the MIT License. Not affiliated with Bootstrap or shadcn/ui.