Overlays

Drawer

Edge-anchored modal or non-modal panel for secondary navigation, settings, and bottom sheets.

import { Drawer } from '@lostgradient/cinder';
overlaydialog
01

Overview

Reference usage

Edge-anchored overlay panel for supplementary content without leaving the current page. The placement prop picks the edge: left, right (default), or bottom for mobile-style bottom sheets. Drawer is modal by default. Set modal={false} for an <aside> that leaves the page interactive and closes from the shared Escape stack.

For a non-modal drawer that represents a region of the page, keep surface="inset", the default. Use surface="default" for a detail panel beside a master list. The panel paints the selected surface, the fades use the same color, and the header, body and footer are transparent. Modal drawers ignore surface.

A bottom drawer is a sheet, and every sheet follows the same rules (design rows 05d, 05j):

  • Grabber: placement="bottom" shows a 36 by 4 grabber above the header. It is decorative; set dragHandleVisible={false} to omit it. With detents it is the resize control instead (see Detents below).
  • Keyboard and height: while a bottom drawer is open it rides above the on-screen keyboard (--_cinder-keyboard-inset, published only while it is open) and its 90dvh cap shrinks by the keyboard, so on a short viewport the body scrolls inside the sheet instead of the sheet outgrowing the screen.
  • Reduced motion: the drawer and every sheet cross-fade instead of sliding when the person asked for less motion. The fade is played from script, because foundation.css forces every CSS transition and animation to 0.01ms under reduced motion.

Detents

detents (a list of DrawerDetent: peek, medium and large) makes a bottom sheet rest at fixed heights, and bind:detent reads and sets the current one. A sheet with no detents is as tall as its content up to the 90dvh cap.

  • large is the 90dvh cap, medium is half the viewport, and peek is a collapsed bar, a grabber band and a 56px row, that shows the sheet's title and the live count (a polite live region, so a screen reader hears it change). The header, body and footer step aside while the sheet peeks, and the title still names the dialog.
  • Resizing with two or more detents: the grabber is a focusable separator (the WAI-ARIA window splitter). Drag it, or the peek bar, and the sheet follows the pointer and snaps to the nearest detent on release. ArrowUp and ArrowDown step to the next larger and smaller detent, Home and End jump to the smallest and largest, and Enter, Space or a tap steps to the next larger one, wrapping from the largest back to the smallest. Tapping the peek bar opens the sheet and moves focus to the grabber.
  • Detents belong to the bottom sheet: left and right drawers ignore them. Under reduced motion the height change is instant.

DrawerDetent is exported alongside DrawerPlacement and DrawerSize.

Side drawer headers use the same padding at the top and inline edges. Set closeButtonVisible={false} when a custom header provides its own accessible close button. Escape closes a modal drawer. A backdrop click dismisses it only when the press starts and the click ends on the backdrop.

Set fitContent to place the footer directly below a short body. Long content still scrolls above a footer pinned to the bottom of the panel. Keep the body's keyboard focus ring so users who tab to the scrolling region can see where focus landed.

  • Footer: on a bottom sheet the footer slot is a bar on the sheet's surface rather than a strip over the content. The body scrolls under a 24px fade that ends at the bar's top edge in place of a hard rule, so the call to action never floats over a row, and the bar's bottom padding keeps clear of a bottom safe area. Side drawers keep their ruled footer.
  • Content never shrinks: the body is a block scroller, so a body that outgrows the sheet scrolls and its rows keep their height; a rule keeps that true if a consumer's class makes the body a flex column.
  • Header bar: a bottom sheet with an action snippet draws its default header as three columns: the close control at the start (closeLabel="Cancel" reads as a text button), the title centred as a 14px semibold label rather than a page heading, and action at the end. The DOM order stays title, close, action, so focus order is Cancel then the action.

Choosing this component

  • Showing detail or edit forms alongside a list or table where the user needs to stay in context.
  • Navigation trees, filter panels, or settings that the user may want to keep open while interacting with the page.
  • Secondary workflows that complement the current view rather than replacing it.
  • Mobile-first surfaces that should slide up from the bottom of the viewport — use placement="bottom", optionally with dragHandleVisible.

Choosing something else

  • Full-screen workflows that require the user's full attention — use a Modal or navigate to a new page.
  • Brief contextual explanations or single-action prompts — use a Popover instead.
  • Modal — blocking full-attention overlay when the user cannot continue without acting.
  • Sidebar — persistent side panel that is always visible (not overlaid).

Usage

svelte
<script lang="ts">
  import { Button } from '@lostgradient/cinder';
  import { Checkbox } from '@lostgradient/cinder';
  import { Drawer } from '@lostgradient/cinder';

  let open = $state(false);
  let triggerRef: HTMLElement | null = $state(null);

  const filters = Array.from({ length: 30 }, (_, index) => ({
    id: `drawer-overflowing-filter-${index + 1}`,
    label: `Filter group ${index + 1}`,
  }));
</script>

<Button
  label="Open drawer"
  onclick={(event: MouseEvent) => {
    triggerRef = event.currentTarget as HTMLElement;
    open = true;
  }}
/>

<Drawer bind:open title="Filters" {triggerRef}>
  <div style="display: grid; gap: 0.75rem;">
    {#each filters as filter (filter.id)}
      <Checkbox id={filter.id} label={filter.label} />
    {/each}
  </div>

  {#snippet footer()}
    <Button variant="secondary" label="Cancel" onclick={() => (open = false)} />
    <Button label="Apply" onclick={() => (open = false)} />
  {/snippet}
</Drawer>

Title

Pass a string or a snippet to title. The default header renders it in an <h2>, so a snippet must emit phrasing content such as text and <code>. Supply titleText with a snippet. Drawer uses that plain text for its accessible name, the hidden heading when a custom header needs a label, and the sheet's peek bar.

Live preview

Basic drawer

02

When to use

Use when
  • Showing secondary navigation, filters or settings at the edge of a page.
  • Use surface="default" for a non-modal detail panel beside a list. Keep the inset surface for separate page regions.
  • Use closeButtonVisible=false for a custom accessible close button. Use fitContent for a footer near short content.
  • Presenting a touch task in a bottom sheet using placement="bottom".
  • Showing an identifier in a phrasing-content title snippet. Use titleText to name the dialog and its sheet peek bar.
Avoid when
  • Interrupting the user for a focused decision — use modal so the surface is centered and task-scoped.
  • Anchoring a small surface to a trigger — use popover instead.
03

Examples

Basic drawer

An edge-anchored slide-in panel with controls for placement, size, and triggerRef.

Bottom sheet

A bottom-placed drawer with a drag handle and enough content to scroll.

Bottom sheet with detents

A bottom sheet that rests at peek, medium or large. The grabber is the resize control, the peek bar shows a live count, and the footer holds the action.

Overflowing drawer

A side drawer with a scrollable body.

04

Props

Props for drawer
Name
Type
Default
Description
open bindable boolean false Whether the drawer is open. Bindable via bind:open.
placement 'left' | 'right' | 'bottom' 'right' Edge the drawer slides in from.
size 'xs''sm''md''lg''xl' 'md' Drawer width token for left/right placements. Ignored for placement="bottom", which always spans the full viewport width and caps its height at 90dvh. xs is 280px, the width of a navigation drawer; sm is 360px, md 448px, lg 576px and xl 768px.
closeIconLabel text 'Close drawer' Accessible name of the X icon close button, for a drawer that is not a generic one, such as "Close navigation" on a sidebar's drawer.
closeButtonVisible boolean true Whether to render the built-in close control. A header that sets this to false must offer its own accessible close control.
fitContent boolean false Size the body to its content so the footer follows short content. A long body still scrolls above the footer.
modal boolean true Whether the drawer is modal. Modal drawers use the native dialog top layer, backdrop, body scroll lock, and focus trap. Non-modal drawers render as an aside and leave the page interactive.
surface 'inset' | 'default' 'inset' Non-modal panel surface. Use inset for a region of the page or default for a detail panel beside a master list. Modal drawers ignore this prop.
title required discriminated-union Title rendered in the default heading. In Svelte, a title snippet must emit phrasing content and requires titleText.
titleText text Plain text for a snippet title. Names the drawer and is shown in the hidden heading and sheet peek bar.
triggerRef HTMLElement | null null Optional reference to the element that opened the drawer. When supplied, focus returns to this element on close. When omitted, focus restores to the element that held focus before the drawer opened.
ariaLabelledby text Optional id of an element that names the drawer. When supplied, drawer wires aria-labelledby to this id and renders no internal heading. Use this when a custom header snippet has its own visible heading — supply ariaLabelledby pointing to that heading's id so the visible and accessible names stay in sync.
dragHandleVisible boolean true Whether a placement="bottom" drawer shows the grabber, the small pill above the header that marks it as a sheet. Swipe-to-close is not implemented, so the pill is a visual affordance only, unless the drawer has detents: then the grabber is the resize control and always shows. Ignored for left/right placements. Named dragHandleVisible (not draggable) to avoid colliding with the native HTML draggable attribute on the underlying <dialog>.
closeLabel text Words for the close control. When set, the control is a text button that reads these words ("Close", as on the shared sheets) instead of the X icon, and they are its accessible name. Left out, the control is the X icon named "Close drawer".
detents DrawerDetent[] The heights a placement="bottom" drawer can rest at, from peek, medium and large. Listed in any order, they are used smallest first. With two or more, the grabber becomes a resize control: drag it, press ArrowUp and ArrowDown on it, or tap it, and the sheet snaps to the nearest detent. A single detent fixes the sheet at that height. Left out, the sheet is as tall as its content up to 90% of the viewport. Ignored for left/right placements.
detent bindable 'peek' | 'medium' | 'large' The detent the sheet rests at, one of detents. Bindable via bind:detent. Left out, or not one of detents, the sheet rests at the smallest detent.
count text A live count the collapsed peek bar shows beside the title, such as "12 results". It is a polite live region, so screen readers announce it as it changes. Only the peek bar draws it.
header snippet Custom header. Falls back to a default header that renders title.
children required snippet Drawer body content. Required.
footer snippet Optional footer (e.g. action buttons).
action snippet The primary action of a bottom sheet's header, such as "Apply" or "Done", drawn at the trailing edge. With it, the sheet's default header is a three-column bar: the close control at the start (a text "Cancel" when closeLabel says so), the title centred as a small label, and this action at the end. Ignored for left/right placements and next to a custom header.
onExitComplete () => void Called once a close has fully finished: after the modal drawer's exit transition and unmount, or as soon as a non-modal drawer closes. A consumer that wraps Drawer in its own {#if} clears that gate here, so the exit transition plays before the instance is destroyed.