Skip to content

Drawer

A panel that rises from the bottom of the screen. Drag it down, press Esc or tap outside to close it. Same markup and props in every style: switch the style in the header to see it change.

Basic

A short form. Drag the handle or the title down to close it; on wide screens it stays a comfortable width. In HTML, add data-vin-drawer for dragging (vinui.js).

Daily goal

How many minutes do you want to practise each day?

drawer-basic.html
<button type="button" class="vin-btn vin-btn--outline" commandfor="drawer-goal" command="show-modal">Set daily goal</button>
<dialog class="vin-dialog vin-sheet vin-drawer" id="drawer-goal" data-side="bottom" aria-labelledby="drawer-goal-title" aria-describedby="drawer-goal-desc" closedby="any" data-vin-drawer>
  <div class="vin-dialog__header">
    <h2 class="vin-dialog__title" id="drawer-goal-title">Daily goal</h2>
    <p class="vin-dialog__description" id="drawer-goal-desc">How many minutes do you want to practise each day?</p>
  </div>
  <div class="vin-dialog__body">
    <div class="vin-field">
      <label class="vin-label" for="drawer-goal-min">Minutes a day</label>
      <input id="drawer-goal-min" class="vin-input" type="number" inputmode="numeric" min="5" max="240" step="5" value="30">
    </div>
  </div>
  <div class="vin-dialog__footer">
    <button type="button" class="vin-btn vin-btn--outline" commandfor="drawer-goal" command="close">Cancel</button>
    <button type="button" class="vin-btn" commandfor="drawer-goal" command="close">Save goal</button>
  </div>
  <button type="button" class="vin-btn vin-btn--ghost vin-btn--icon vin-dialog__close" commandfor="drawer-goal" command="close" aria-label="Close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
</dialog>

Actions

A list of actions, like a phone's share sheet.

Sunset over the bay.jpg

drawer-actions.html
<button type="button" class="vin-btn vin-btn--outline" commandfor="drawer-photo" command="show-modal">Photo options</button>
<dialog class="vin-dialog vin-sheet vin-drawer" id="drawer-photo" data-side="bottom" aria-labelledby="drawer-photo-title" closedby="any" data-vin-drawer>
  <div class="vin-dialog__header">
    <h2 class="vin-dialog__title" id="drawer-photo-title">Sunset over the bay.jpg</h2>
  </div>
  <div class="vin-dialog__body">
    <button type="button" class="vin-btn vin-btn--ghost" commandfor="drawer-photo" command="close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/><path d="M12 15V3"/></svg>Save to device</button>
    <button type="button" class="vin-btn vin-btn--ghost" commandfor="drawer-photo" command="close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7"/><path d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7"/></svg>Copy link</button>
    <button type="button" class="vin-btn vin-btn--ghost" commandfor="drawer-photo" command="close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>Report a problem</button>
  </div>
  <button type="button" class="vin-btn vin-btn--ghost vin-btn--icon vin-dialog__close" commandfor="drawer-photo" command="close" aria-label="Close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
</dialog>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add drawer
React
import { Drawer, DrawerClose } from "@/components/vin/drawer";
Vue
import Drawer, { DrawerClose } from "@/components/vin/drawer.vue";
Svelte
import Drawer from "$lib/components/vin/drawer.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/drawer.json, which every framework version is tested against.

PropValuesDefaultIn HTML
trigger / title / description / footer
The same as Dialog.
boolean—the Dialog parts inside dialog.vin-dialog.vin-sheet.vin-drawer[data-side=bottom]
open / defaultOpen
Use onOpenChange to hear about changes.
boolean——
dismissible
Close on a tap outside and on a drag down.
booleantrueclosedby="any"

Parts

React, Vue, SvelteHTML classes
<Drawer><DrawerClose>.vin-drawer

Accessibility

  • It is the browser's modal <dialog>: focus is trapped inside, Esc closes it and focus returns to the button that opened it.
  • Dragging is a shortcut, never the only way: Esc, a tap outside and the close button all work too.
  • The handle is drawn with CSS, so screen readers don't announce an unlabelled control.
  • With reduced motion, it fades instead of sliding.