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).
<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>import { Drawer, DrawerClose } from "@/components/vin/drawer";
import { Button } from "@/components/vin/button";
import { Field } from "@/components/vin/input";
export function DrawerBasic() {
return (
<Drawer
trigger={<Button variant="outline">Set daily goal</Button>}
title="Daily goal"
description="How many minutes do you want to practise each day?"
footer={
<>
<DrawerClose><Button variant="outline">Cancel</Button></DrawerClose>
<DrawerClose><Button>Save goal</Button></DrawerClose>
</>
}
>
<Field label="Minutes a day" type="number" inputMode="numeric" min={5} max={240} step={5} defaultValue={30} />
</Drawer>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Drawer, { DrawerClose } from "@/components/vin/drawer.vue";
import Button from "@/components/vin/button.vue";
import Field from "@/components/vin/input.vue";
</script>
<template>
<Drawer title="Daily goal" description="How many minutes do you want to practise each day?">
<template #trigger><Button variant="outline">Set daily goal</Button></template>
<Field label="Minutes a day" type="number" inputmode="numeric" :min="5" :max="240" :step="5" default-value="30" />
<template #footer>
<DrawerClose><Button variant="outline">Cancel</Button></DrawerClose>
<DrawerClose><Button>Save goal</Button></DrawerClose>
</template>
</Drawer>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Drawer from "$lib/components/vin/drawer.svelte";
import Button from "$lib/components/vin/button.svelte";
import Field from "$lib/components/vin/input-field.svelte";
</script>
<Drawer title="Daily goal" description="How many minutes do you want to practise each day?">
{#snippet trigger(props)}<Button variant="outline" {...props}>Set daily goal</Button>{/snippet}
<Field label="Minutes a day" type="number" inputmode="numeric" min={5} max={240} step={5} value={30} />
{#snippet footer(close)}
<Button variant="outline" onclick={close}>Cancel</Button>
<Button onclick={close}>Save goal</Button>
{/snippet}
</Drawer>Actions
A list of actions, like a phone's share sheet.
<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>import * as React from "react";
import { Drawer, DrawerClose } from "@/components/vin/drawer";
import { Button } from "@/components/vin/button";
const Icon = ({ children }: { children: React.ReactNode }) => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">{children}</svg>
);
export function DrawerActions() {
return (
<Drawer trigger={<Button variant="outline">Photo options</Button>} title="Sunset over the bay.jpg">
<DrawerClose><Button variant="ghost"><Icon><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" /></Icon>Save to device</Button></DrawerClose>
<DrawerClose><Button variant="ghost"><Icon><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" /></Icon>Copy link</Button></DrawerClose>
<DrawerClose><Button variant="ghost"><Icon><circle cx="12" cy="12" r="9" /><path d="M12 8v4" /><path d="M12 16h.01" /></Icon>Report a problem</Button></DrawerClose>
</Drawer>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Drawer, { DrawerClose } from "@/components/vin/drawer.vue";
import Button from "@/components/vin/button.vue";
</script>
<template>
<Drawer title="Sunset over the bay.jpg">
<template #trigger><Button variant="outline">Photo options</Button></template>
<DrawerClose>
<Button variant="ghost">
<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>
</DrawerClose>
<DrawerClose>
<Button variant="ghost">
<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>
</DrawerClose>
<DrawerClose>
<Button variant="ghost">
<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>
</DrawerClose>
</Drawer>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Drawer from "$lib/components/vin/drawer.svelte";
import Button from "$lib/components/vin/button.svelte";
</script>
<Drawer title="Sunset over the bay.jpg">
{#snippet trigger(props)}<Button variant="outline" {...props}>Photo options</Button>{/snippet}
{#snippet children(close)}
<Button variant="ghost" onclick={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 variant="ghost" onclick={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 variant="ghost" onclick={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>
{/snippet}
</Drawer>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:
npx @vinish/ui add drawerimport { Drawer, DrawerClose } from "@/components/vin/drawer";import Drawer, { DrawerClose } from "@/components/vin/drawer.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
trigger / title / description / footerThe same as Dialog. | boolean | — | the Dialog parts inside dialog.vin-dialog.vin-sheet.vin-drawer[data-side=bottom] |
open / defaultOpenUse onOpenChange to hear about changes. | boolean | — | — |
dismissibleClose on a tap outside and on a drag down. | boolean | true | closedby="any" |
Parts
| React, Vue, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.