PeakUI

Drawer

Edge-docked panel overlay with drag to dismiss

Usage

import {Drawer} from "@peakui/react";

Anatomy

import {Button, Drawer} from "@peakui/react";

export default () => (
  <Drawer>
    <Button>Open drawer</Button>
    <Drawer.Backdrop>
      <Drawer.Content>
        <Drawer.Dialog>
          <Drawer.Handle /> {/* Optional: drag affordance */}
          <Drawer.CloseTrigger /> {/* Optional: close button */}
          <Drawer.Header>
            <Drawer.Heading />
          </Drawer.Header>
          <Drawer.Body />
          <Drawer.Footer />
        </Drawer.Dialog>
      </Drawer.Content>
    </Drawer.Backdrop>
  </Drawer>
);

Examples

Placements

Scrolling Body

Controlled State

Backdrop Variants

Dismiss Behavior

Customization

Tailwind CSS

Global CSS

@layer components {
  .drawer__backdrop {
    @apply bg-linear-to-br from-black/50 to-black/70;
  }

  .drawer__dialog {
    @apply rounded-2xl border border-white/10 shadow-2xl;
  }

  .drawer__header {
    @apply text-center;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Drawer component uses these CSS classes (view source styles):

Base & Element Classes

  • .drawer__trigger - Trigger element that opens the drawer
  • .drawer__backdrop - Overlay behind the drawer
  • .drawer__content - Positioning wrapper docked to an edge
  • .drawer__dialog - The drawer panel
  • .drawer__header - Header section for the title
  • .drawer__heading - Heading element styles
  • .drawer__body - Scrollable content area
  • .drawer__footer - Footer section for actions
  • .drawer__handle - Drag handle indicator
  • .drawer__close-trigger - Close button position styles

Backdrop Variant Classes

  • .drawer__backdrop--opaque - Dimmed backdrop (default)
  • .drawer__backdrop--blur - Blurred backdrop
  • .drawer__backdrop--transparent - Transparent backdrop

Placement Classes

  • .drawer__content--bottom - Docks to the bottom edge (default)
  • .drawer__content--top - Docks to the top edge
  • .drawer__content--left - Docks to the left edge
  • .drawer__content--right - Docks to the right edge
  • .drawer__dialog--bottom
  • .drawer__dialog--top
  • .drawer__dialog--left - Full-height side panel
  • .drawer__dialog--right - Full-height side panel

Slots

  • [data-slot="drawer-trigger"] - The Drawer.Trigger element
  • [data-slot="drawer-backdrop"] - The Drawer.Backdrop overlay
  • [data-slot="drawer-content"] - The Drawer.Content positioning wrapper
  • [data-slot="drawer-dialog"] - The Drawer.Dialog panel
  • [data-slot="drawer-header"] - The Drawer.Header element
  • [data-slot="drawer-heading"] - The Drawer.Heading element
  • [data-slot="drawer-body"] - The Drawer.Body element
  • [data-slot="drawer-footer"] - The Drawer.Footer element
  • [data-slot="drawer-handle"] - The Drawer.Handle element
  • [data-slot="drawer-handle-bar"] - The bar inside Drawer.Handle
  • [data-slot="drawer-close-trigger"] - The Drawer.CloseTrigger element; it renames CloseButton's slot through the typed data-slot prop

CSS Variables

VariablePurpose
--drawer-enter-durationSlide-in duration (250ms)
--drawer-exit-durationSlide-out duration (200ms)
--drawer-enter-easeSlide-in easing
--drawer-exit-easeSlide-out easing

Interactive States

The overlay parts carry React Aria animation states:

  • Entering: [data-entering="true"]
  • Exiting: [data-exiting="true"]
  • Placement: [data-placement="bottom | top | left | right"] on content and dialog
  • Draggable: [data-dismissable="true"] on the dialog

The trigger supports both pseudo-classes and data attributes:

  • Focus: :focus-visible or [data-focus-visible="true"]
  • Disabled: :disabled or [aria-disabled="true"]
  • Pressed: :active or [data-pressed="true"]

API Reference

Drawer

PropTypeDefaultDescription
childrenReact.ReactNode-The trigger element followed by the overlay
stateUseOverlayStateReturn-Overlay state from useOverlayState()
...restDialogTriggerProps-React Aria DialogTrigger attributes

Drawer.Trigger

PropTypeDefaultDescription
childrenReact.ReactNode-Trigger content
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restButtonProps-React Aria Button attributes

Drawer.Backdrop

PropTypeDefaultDescription
variant"opaque" | "blur" | "transparent""opaque"Backdrop overlay style
isDismissablebooleantrueClose on backdrop click and on drag; false disables both
isKeyboardDismissDisabledbooleanfalseDisable the Escape key
isOpenboolean-Controlled open state
defaultOpenbooleanfalseInitially open, without controlling
onOpenChange(isOpen: boolean) => void-Open state change handler
UNSTABLE_portalContainerHTMLElement-Custom portal container
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restModalOverlayProps-React Aria ModalOverlay attributes

Drawer.Content

PropTypeDefaultDescription
placement"bottom" | "top" | "left" | "right""bottom"Edge the panel docks to
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restModalProps-React Aria Modal attributes

Drawer.Dialog

PropTypeDefaultDescription
childrenReact.ReactNode | (({close}) => React.ReactNode)-Content, or a function receiving close
role"dialog" | "alertdialog""dialog"ARIA role
aria-labelstring-Accessible name when no Drawer.Heading is present
aria-labelledbystring-ID of the labelling element; set from Drawer.Heading
aria-describedbystring-ID of the describing element
classNamestring-Additional classes
...restDialogProps-React Aria Dialog attributes

Drawer.Header

PropTypeDefaultDescription
childrenReact.ReactNode-Header content
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

Drawer.Heading

PropTypeDefaultDescription
childrenReact.ReactNode-Heading text; labels the dialog via aria-labelledby
classNamestring-Additional classes
...restHeadingProps-React Aria Heading attributes

Drawer.Body

PropTypeDefaultDescription
childrenReact.ReactNode-Body content; scrolls on its own and never starts a drag. Add tabIndex={0} when it overflows so the keyboard can reach it
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

Drawer.Footer

PropTypeDefaultDescription
childrenReact.ReactNode-Footer content, usually buttons
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

Drawer.Handle

PropTypeDefaultDescription
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'. Hidden from assistive technology
...restHTMLAttributes-The attributes of the rendered element

Drawer.CloseTrigger

PropTypeDefaultDescription
childrenReact.ReactNode-Custom close button content; defaults to the cross glyph
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restButtonProps-React Aria Button attributes; slot defaults to "close"

Render Props

PropTypeDescription
Drawer.Backdrop className(renderProps: ModalOverlayRenderProps) => stringComputes classes from isEntering, isExiting and state
Drawer.Content className(renderProps: ModalRenderProps) => stringComputes classes from isEntering, isExiting and state
Drawer.Dialog children(opts: {close: () => void}) => React.ReactNodeRenders content with a callback that closes the drawer

On this page