Knit UI
GitHub

Playground

Loading playground…

false
true
false
false
false
Playground
<Drawer
  opened={false}
  position="left"
  size="md"
  withCloseButton
  title="Drawer title"
>
  Drawer body content goes here.
</Drawer>

Examples

Trigger

A trigger button that opens and closes the drawer — demonstrates controlled open state.

Loading example…

TriggerSourceStorybook

Positions

All four anchor positions side by side — each button opens its drawer from a different edge.

Loading example…

PositionsSourceStorybook

Sizes

All seven size steps, opening the same left-anchored drawer at increasing widths.

Loading example…

SizesSourceStorybook

No Title

Drawer without a title — the header is omitted entirely.

Loading example…

No TitleSourceStorybook

Without Close Button

Close button hidden via withCloseButton={false} — only click-outside or Escape closes it.

Loading example…

Without Close ButtonSourceStorybook

With Offset

Drawer with an offset that creates a gap between the panel and the viewport edge.

Loading example…

With OffsetSourceStorybook

Shadows

All five shadow levels across the shared elevation ladder. Rendered on the static Drawer.Content part (each in its own contained, non-overlapping cell) so the drop shadows are directly comparable without the portaled overlay. The live drawer defaults to shadow="xl".

Loading example…

ShadowsSourceStorybook

Compound API

Compound API — assembling the drawer manually with Drawer.Header, Drawer.Title, and Drawer.Body.

Loading example…

Compound APISourceStorybook

Styles

Per-slot styles targets individual parts — here the overlay, content, and title.

Loading example…

StylesSourceStorybook

Drag To Dismiss

Drag-to-dismiss (dragToDismiss) — drag the panel toward its anchored edge to close it (the same reanimated + gesture mechanic as @knitui/sheet): a left drawer drags left, a bottom drawer drags down, etc. The CSS enter/exit slide is unchanged. Release past ~30% of the panel extent (or a fling toward the edge) dismisses; a short drag springs back.

Loading example…

Drag To DismissSourceStorybook

Props

PropTypeDefaultDescription
onClose required() => voidCalled when the overlay requests to close (Escape, overlay click, close button).
opened requiredbooleanfalseControlled opened state.
animationfalse | MotionPresetName | MotionPreset | undefineda subtle edge slide-in keyed to `position`. Reduced motion is always honoured. Exit animates (the panel slides and scrim fades out before unmounting) unless `keepMounted` is set.Enter/exit animation — a motion preset name, an inline {@link MotionPreset}, or `false` to disable.
animationConfigSpringConfig | undefinedSpring config for the drag settle (reanimated `withSpring`).
aria-describedbystring | undefinedAdditional content description id(s).
aria-labelstring | undefined"Drawer"Accessible label used when no visible title is provided.
childrenReactNodeDrawer body content goes here.Drawer body content.
closeButtonProps{ "aria-label"?: string; } | undefinedTyped, cross-platform-safe subset of close-button props.
closeOnClickOutsideboolean | undefinedtrueClose when the user clicks the overlay scrim.
closeOnEscapeboolean | undefinedtrueClose when the user presses Escape (web).
disabled systemboolean | undefined
dragThresholdnumber | undefined0.3Distance dragged toward the edge, as a fraction of the panel extent, past which releasing dismisses (a fling toward the edge always dismisses).
dragToDismissboolean | undefinedfalseAllow dragging the panel toward its anchored edge to dismiss (reanimated + gesture, the same mechanic as `@knitui/sheet`). The CSS enter/exit slide is unchanged; this only adds the interactive drag-to-close.
durationnumber | undefinedAnimation speed in ms — overrides the preset's duration while keeping its easing. Ignored when `animation` is `false` or reduced motion is on.
keepMountedboolean | undefinedfalseKeep mounted while closed (toggles `display:"none"` instead of unmounting).
lockScrollboolean | undefinedtrueLock body scroll while opened (web).
offsetnumber | SpaceTokens | Animated.AnimatedNode | "safe" | null | undefined"$0"Gap between the panel and the viewport edge. Prefer `$space` tokens.
overlayAnimationfalse | MotionPresetName | MotionPreset | undefined"fade". Reduced motion is always honoured. The content frame's own animation is supplied separately by the consumer (`Modal`/`Drawer`) on its content frame; pass `false` here to keep the scrim in lockstep when the consumer disables that.Enter/exit animation for the overlay scrim — a motion preset name, an inline {@link MotionPreset}, or `false` to disable.
overlayPropsOverlayProps | undefinedProps forwarded to the underlying `Overlay` scrim.
positionDrawerPosition | undefined
left · right · top · bottom
"left"Viewport edge the drawer is anchored to.
radius systemstring | number | undefinedPanel corner radius.
returnFocusboolean | undefinedtrueReturn focus to the previously-focused element on close (web).
shadow system"xs" | "sm" | "md" | "lg" | "xl" | "xxs" | "xxl" | undefined
unset · xs · sm · md · lg · xl
Elevation — drop shadow from the shared ladder.
size systemstring | number | undefined
xxs · xs · sm · md · lg · xl · xxl
"md"Panel extent — width for left/right, height for top/bottom.
styles systemDrawerStyles | undefinedUniform per-slot style passthrough. See {@link DrawerStyles}.
theme systemThemeName | null | undefinedApplies a theme to this element
titleReactNodeDrawer titleDrawer title rendered in the header.
trapFocusboolean | undefinedtrueTrap keyboard focus within the content while opened (web; no-op on native).
withCloseButtonboolean | undefinedtrueShow or hide the close button in the header.
withinPortalboolean | undefinedtrueRender inside a `Portal`.
withOverlayboolean | undefinedtrueRender the overlay scrim.
zIndexnumber | undefined200Root `z-index`.

Style slots

Every part of Drawer can be styled through the styles prop. Explicit props on the component always win over slot styles.

SlotUsage
bodystyles={{ body: { … } }}
closeButtonstyles={{ closeButton: { … } }}
contentstyles={{ content: { … } }}
headerstyles={{ header: { … } }}
overlaystyles={{ overlay: { … } }}
titlestyles={{ title: { … } }}
Accessibility & DOM props (2)
PropType
keyKey | null | undefined
refRef<TamaguiElement> | undefined

Plus 494 inherited style props from Box — the full Tamagui/React Native style surface, including token shorthands like p, mx, bg and c. See Tokens for the scales they accept, or the full list.