Skip to main content
Kobalte

Drawer

Since v2.0.0@kobalte/core/drawerSourceDialog

A panel that slides in from the edge of the screen with drag-to-dismiss and snap-point support. Built on Dialog with a two-signal open pattern so content stays mounted during the closing animation.

Import

import { Drawer } from "@kobalte/core/drawer";
// or
import {
Root,
Trigger,
Content,
Overlay,
Portal,
CloseButton,
Title,
Description,
} from "@kobalte/core/drawer";

Features

  • Slides in from any of the four edges (bottom, top, left, right).
  • Drag-to-dismiss with configurable snap points and velocity-based release.
  • Overlay opacity tracks the drag position in real time.
  • Scrollable children are handled automatically — the drag gesture does not conflict with internal scrolling.
  • Snap points accept fractional values (0–1) or absolute pixel strings ("200px").
  • Programmatic snap-point control via useContext().setActiveSnapPoint.
  • Supports modal and non-modal modes.
  • Focus is trapped and scroll is locked when modal.
  • Pressing Esc closes the drawer.
  • Can be controlled or uncontrolled.

Anatomy

  • Drawer: Contains all the parts of a drawer.
  • Drawer.Trigger: The button that opens the drawer.
  • Drawer.Portal: Portals its children into the body when the drawer is open.
  • Drawer.Overlay: The layer that covers the inert portion of the view when the drawer is open. Opacity is driven automatically by openPercentage.
  • Drawer.Content: Contains the content rendered when the drawer is open. Handles all pointer and touch drag gestures.
  • Drawer.CloseButton: The button that closes the drawer.
  • Drawer.Title: An accessible title announced when the drawer is opened.
  • Drawer.Description: An optional accessible description announced when the drawer is opened.
<Drawer>
<Drawer.Trigger />
<Drawer.Portal>
<Drawer.Overlay />
<Drawer.Content>
<Drawer.CloseButton />
<Drawer.Title />
<Drawer.Description />
</Drawer.Content>
</Drawer.Portal>
</Drawer>

Example

import { Drawer } from "@kobalte/core/drawer";
import { CrossIcon } from "some-icon-library";
import "./style.css";
function App() {
return (
<Drawer side="bottom">
<Drawer.Trigger class="drawer__trigger">Open drawer</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Overlay class="drawer__overlay" />
<Drawer.Content class="drawer__content">
<div class="drawer__handle" />
<div class="drawer__header">
<Drawer.Title class="drawer__title">Drawer</Drawer.Title>
<Drawer.CloseButton class="drawer__close-button">
<CrossIcon />
</Drawer.CloseButton>
</div>
<Drawer.Description class="drawer__description">
Drag the handle or swipe down to dismiss.
</Drawer.Description>
</Drawer.Content>
</Drawer.Portal>
</Drawer>
);
}
.drawer__trigger {
display: inline-flex;
align-items: center;
justify-content: center;
height: 40px;
padding: 0 16px;
border: none;
border-radius: 6px;
background-color: hsl(200 98% 39%);
color: white;
font-size: 16px;
cursor: pointer;
}
/* Opacity is driven by JS (openPercentage). Only a CSS transition is needed. */
.drawer__overlay {
position: fixed;
inset: 0;
z-index: 50;
background-color: rgb(0 0 0 / 0.4);
transition: opacity 350ms cubic-bezier(0.32, 0.72, 0, 1);
}
.drawer__content {
position: fixed;
z-index: 50;
bottom: 0;
left: 0;
width: 100%;
height: 320px;
background-color: white;
border-radius: 12px 12px 0 0;
border-top: 1px solid hsl(240 5% 84%);
padding: 16px 24px 32px;
outline: none;
/* The drawer applies transform via inline style. This transition animates it. */
transition: transform 350ms cubic-bezier(0.32, 0.72, 0, 1);
}
.drawer__handle {
width: 48px;
height: 4px;
background-color: hsl(240 5% 84%);
border-radius: 9999px;
margin: 0 auto 16px;
}
.drawer__header {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 8px;
}
.drawer__close-button {
height: 16px;
width: 16px;
color: hsl(240 5% 34%);
}
.drawer__title {
font-size: 18px;
font-weight: 500;
color: hsl(240 6% 10%);
}
.drawer__description {
font-size: 14px;
color: hsl(240 5% 26%);
}

Usage

Side

Use the side prop to control which edge of the viewport the drawer slides in from.

<Drawer side="right">...</Drawer>
<Drawer side="left">...</Drawer>
<Drawer side="top">...</Drawer>
<Drawer side="bottom">...</Drawer> {/* default */}

The Drawer.Content must be positioned against the matching edge:

/* right drawer */
.drawer__content {
position: fixed;
top: 0;
right: 0;
height: 100%;
width: 320px;
transition: transform 350ms cubic-bezier(0.32, 0.72, 0, 1);
}
/* bottom drawer */
.drawer__content {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 320px;
transition: transform 350ms cubic-bezier(0.32, 0.72, 0, 1);
}

Snap points

Snap points define the positions the drawer can settle at. Each value is either a fraction of the drawer size (0 = fully closed, 1 = fully open) or a pixel string ("200px").

// Three snap points: closed, 40% peek, fully open
<Drawer side="bottom" snapPoints={[0, 0.4, 1]} defaultSnapPoint={0.4}>
...
</Drawer>
// Pixel-based snap point
<Drawer side="bottom" snapPoints={[0, "200px", 1]}>
...
</Drawer>

defaultSnapPoint sets which snap point the drawer opens to. Defaults to 1 (fully open).

Default open

<Drawer defaultOpen>...</Drawer>

Controlled open

The open prop makes the open state controlled. The onOpenChange event fires whenever the user interacts with the trigger, overlay, close button, or escape key.

import { createSignal } from "solid-js";
function ControlledExample() {
const [open, setOpen] = createSignal(false);
return (
<Drawer open={open()} onOpenChange={setOpen}>
...
</Drawer>
);
}

Programmatic snap

Access setActiveSnapPoint from context to snap to a specific position without dragging.

import { Drawer } from "@kobalte/core/drawer";
function SnapButtons() {
const ctx = Drawer.useContext();
return (
<>
<button onClick={() => ctx.setActiveSnapPoint(0.4)}>Peek</button>
<button onClick={() => ctx.setActiveSnapPoint(1)}>Expand</button>
</>
);
}
function App() {
return (
<Drawer snapPoints={[0, 0.4, 1]}>
<Drawer.Trigger>Open</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Overlay class="drawer__overlay" />
<Drawer.Content class="drawer__content">
<SnapButtons />
</Drawer.Content>
</Drawer.Portal>
</Drawer>
);
}

Non-modal

Set modal={false} to keep the background interactive and remove the overlay. Focus is not trapped.

<Drawer side="right" modal={false}>
<Drawer.Trigger>Open</Drawer.Trigger>
<Drawer.Portal>
{/* No Drawer.Overlay */}
<Drawer.Content class="drawer__content">...</Drawer.Content>
</Drawer.Portal>
</Drawer>

Drag handle

Add a visible drag handle to hint that the drawer is draggable. Any element inside Drawer.Content is draggable by default — use data-no-drag to opt specific elements out.

<Drawer.Content class="drawer__content">
<div class="drawer__handle" />
...
{/* This element will not initiate a drag */}
<div data-no-drag>Non-draggable region</div>
</Drawer.Content>

Animating the overlay

Drawer.Overlay automatically drives its opacity from the drawer's openPercentage (0 when fully closed, 1 when fully open). This means opacity tracks the drag position in real time with no extra JavaScript.

To animate the opacity on open/close, add a CSS transition:

.drawer__overlay {
position: fixed;
inset: 0;
background-color: rgb(0 0 0 / 0.4);
/* opacity changes will be animated */
transition: opacity 350ms cubic-bezier(0.32, 0.72, 0, 1);
}

The transition is automatically suppressed during drag so the opacity follows the finger instantly.

Custom damping and velocity

Control the rubber-band feel when dragging past the most-open snap point, and the velocity threshold for snap selection on release.

<Drawer
// Custom logarithmic rubber-band (default)
dampFunction={distance => 6 * Math.log(distance + 1)}
// Custom velocity: use raw distance/time ratio with no clamping
velocityFunction={(distance, time) => distance / time}
// Reset velocity window every 100ms (default: 200)
velocityCacheReset={100}
// Prevent fast flings from skipping intermediate snap points
allowSkippingSnapPoints={false}
>
...
</Drawer>

API Reference

Drawer

Drawer is equivalent to the Root import from @kobalte/core/drawer.

PropDescription
openboolean
The controlled open state of the drawer.
defaultOpenboolean
The default open state when initially rendered. Useful when you do not need to control the open state.
onOpenChange(open: boolean) => void
Event handler called when the open state changes.
side"bottom" | "top" | "left" | "right"
Which edge of the viewport the drawer slides in from. Default: "bottom"
snapPointsDrawerSize[]
Positions the drawer can settle at. Each value is a fraction (0–1) or a pixel string ("200px"). 0 = fully closed, 1 = fully open. Default: [0, 1]
breakPoints(DrawerSize | null)[]
Custom thresholds between adjacent snap points. Length must equal snapPoints.length - 1. Pass null to use the default midpoint.
defaultSnapPointDrawerSize
The snap point the drawer opens to. Default: 1
activeSnapPointDrawerSize
The controlled active snap point.
onActiveSnapPointChange(snapPoint: DrawerSize) => void
Event handler called when the active snap point changes.
dampFunction(distance: number) => number
Controls rubber-band resistance when dragging past the most-open snap point. Default: (d) => 6 * Math.log(d + 1)
velocityFunction(distance: number, time: number) => number
Computes the velocity multiplier used to project the release position for snap selection. Default: d / t, clamped to 1 when |v| < 1
velocityCacheResetnumber
Milliseconds after which the cached drag distance resets for velocity calculation. Default: 200
allowSkippingSnapPointsboolean
Whether a high-velocity release can skip intermediate snap points. Default: true
handleScrollableElementsboolean
Whether the drag gesture yields to scrollable children. Default: true
idstring
A unique identifier for the component. If not provided, a generated id is used.
modalboolean
When true: interaction with outside elements is disabled, scroll is locked, and focus is trapped inside the content. Default: true
preventScrollboolean
Whether scroll should be locked even when modal is false.
translationsDialogIntlTranslations
Localization strings.

Drawer.Content

PropDescription
onOpenAutoFocus(event: Event) => void
Event handler called when focus moves into the content after opening. Can be prevented by calling event.preventDefault.
onCloseAutoFocus(event: Event) => void
Event handler called when focus returns to the trigger after closing. Can be prevented by calling event.preventDefault.
onEscapeKeyDown(event: KeyboardEvent) => void
Event handler called when the escape key is pressed. Can be prevented by calling event.preventDefault.
onPointerDownOutside(event: PointerDownOutsideEvent) => void
Event handler called when a pointer event occurs outside the content. Can be prevented by calling event.preventDefault.
onFocusOutside(event: FocusOutsideEvent) => void
Event handler called when focus moves outside the content. Can be prevented by calling event.preventDefault.
onInteractOutside(event: InteractOutsideEvent) => void
Event handler called when an interaction occurs outside the content. Can be prevented by calling event.preventDefault.
Data attributeDescription
data-sideThe side the drawer appears from: "bottom", "top", "left", or "right".
data-expandedPresent when the drawer is open.
data-closedPresent when the drawer is closed.
data-openingPresent during the open transition.
data-closingPresent during the close transition.
data-snappingPresent while snapping to a snap point after a drag gesture.
data-transitioningPresent during any transition (opening, closing, or snapping).

Drawer.Overlay

Data attributeDescription
data-expandedPresent when the drawer is open.
data-closingPresent during the close transition.
data-transitioningPresent during any transition.

Drawer.Trigger

Drawer.Trigger consists of Button.

Data attributeDescription
data-expandedPresent when the drawer is open.
data-closedPresent when the drawer is closed.

Drawer.useContext

Access the drawer's reactive state from any component inside Drawer. Useful for reading position, building custom controls, or snapping programmatically.

const ctx = Drawer.useContext();
ctx.side(); // DrawerSide — "bottom" | "top" | "left" | "right"
ctx.activeSnapPoint(); // DrawerSize — the current snap point value
ctx.setActiveSnapPoint(); // (snapPoint: DrawerSize) => void
ctx.openPercentage(); // number — 0 (closed) to 1 (open), tracks drag in real time
ctx.translate(); // number — pixel offset from the fully-open position
ctx.isDragging(); // boolean
ctx.isTransitioning(); // boolean
ctx.transitionState(); // null | "opening" | "closing" | "snapping"

Rendered elements

ComponentDefault rendered element
Drawernone
Drawer.Triggerbutton
Drawer.PortalPortal
Drawer.Overlaydiv
Drawer.Contentdiv
Drawer.CloseButtonbutton
Drawer.Titleh2
Drawer.Descriptionp

Accessibility

Keyboard Interactions

KeyDescription
SpaceWhen focus is on the trigger, opens/closes the drawer.
EnterWhen focus is on the trigger, opens/closes the drawer.
TabMoves focus to the next focusable element inside the drawer.
Shift + TabMoves focus to the previous focusable element inside the drawer.
EscCloses the drawer and returns focus to the trigger.

Snap-point architecture and drag math are adapted from corvu/drawer by Jasmin Noetzli (MIT).

Last updated: 11/28/26, 9:28 PM