Components

Drawer

A drawer component for React.

PreviewSource
Example requirements

Also uses: Button.

Installation

Complete the project setup first. The init command configures TypeScript, Vite, Tailwind CSS v4, and Preact compatibility.

CLI

Run init once using the installation guide, then add this component. The CLI copies the required source files and installs their exact dependencies with Bun.

bunx --bun github:LiasCode/shadcn-preact#main add drawer button

Add --dry-run to review the changes. Existing modified files are protected; use --overwrite only when you want to replace them.

Manual installation / degit (optional)

1. Install dependencies

bun add --exact @floating-ui/react-dom@2.1.9 cn@0.4.0 preact@11.0.1 tw-animate-css@1.4.0

The usage example also needs Button. Follow their installation guides as well.

2. Copy the component with degit

Run this from your project root. It selects drawer.tsx, its local dependencies, and both licenses directly from the repository, then copies them into src/components/ui.

bunx degit@3.10.0 https://github.com/LiasCode/shadcn-preact#main ./.cache/shadcn-preact/drawer --files LICENSE.md,registry/ui/drawer.tsx,registry/ui/lib/utils.ts,registry/ui/primitives/LICENSE,registry/ui/primitives/drawer/index.ts,registry/ui/primitives/drawer/parts.tsx,registry/ui/primitives/internals/FloatingFocusManager.tsx,registry/ui/primitives/internals/FloatingPortal.tsx,registry/ui/primitives/internals/FloatingTree.tsx,registry/ui/primitives/internals/FloatingTreeStore.ts,registry/ui/primitives/internals/FocusGuard.tsx,registry/ui/primitives/internals/arrow.ts,registry/ui/primitives/internals/composite/root/CompositeRootContext.ts,registry/ui/primitives/internals/createBaseUIEventDetails.ts,registry/ui/primitives/internals/direction-context.ts,registry/ui/primitives/internals/empty.ts,registry/ui/primitives/internals/getReactElementRef.ts,registry/ui/primitives/internals/getStateAttributesProps.ts,registry/ui/primitives/internals/markOthers.ts,registry/ui/primitives/internals/mergeObjects.ts,registry/ui/primitives/internals/owner.ts,registry/ui/primitives/internals/popups/OverlayContext.ts,registry/ui/primitives/internals/popups/OverlayParts.tsx,registry/ui/primitives/internals/popups/OverlayRoot.tsx,registry/ui/primitives/internals/popups/OverlayTrigger.tsx,registry/ui/primitives/internals/popups/PopupHandle.ts,registry/ui/primitives/internals/popups/TooltipProvider.tsx,registry/ui/primitives/internals/popups/getElementProps.ts,registry/ui/primitives/internals/resolveClassName.ts,registry/ui/primitives/internals/resolveRef.ts,registry/ui/primitives/internals/resolveStyle.ts,registry/ui/primitives/internals/stateAttributesMapping.ts,registry/ui/primitives/internals/tabbable.ts,registry/ui/primitives/internals/types.ts,registry/ui/primitives/internals/useAnchorPositioning.ts,registry/ui/primitives/internals/useAnimationFrame.ts,registry/ui/primitives/internals/useAnimationsFinished.ts,registry/ui/primitives/internals/useButton.ts,registry/ui/primitives/internals/useControlled.ts,registry/ui/primitives/internals/useDismiss.ts,registry/ui/primitives/internals/useFloatingRootContext.ts,registry/ui/primitives/internals/useFocusableWhenDisabled.ts,registry/ui/primitives/internals/useHoverFloatingInteraction.ts,registry/ui/primitives/internals/useId.ts,registry/ui/primitives/internals/useIsoLayoutEffect.ts,registry/ui/primitives/internals/useMergedRefs.ts,registry/ui/primitives/internals/useOnMount.ts,registry/ui/primitives/internals/useOpenChangeComplete.ts,registry/ui/primitives/internals/useRefWithInit.ts,registry/ui/primitives/internals/useRenderElement.ts,registry/ui/primitives/internals/useScrollLock.ts,registry/ui/primitives/internals/useStableCallback.ts,registry/ui/primitives/internals/useTransitionStatus.ts,registry/ui/primitives/internals/visuallyHidden.ts,registry/ui/primitives/merge-props/index.ts --force
mkdir -p ./src/components/ui
cp -R ./.cache/shadcn-preact/drawer/registry/ui/. ./src/components/ui/
cp ./.cache/shadcn-preact/drawer/LICENSE.md ./src/components/ui/LICENSE.md

The temporary copy lives in .cache/shadcn-preact/drawer. Existing components stay in place; shared source files are updated from main.

Selected source files (54)

Usage

import { Button } from "./components/ui/button";
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "./components/ui/drawer"
<Drawer>
  <DrawerTrigger render={<Button variant="outline" />}>Open</DrawerTrigger>
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle>Are you absolutely sure?</DrawerTitle>
      <DrawerDescription>This action cannot be undone.</DrawerDescription>
    </DrawerHeader>
    <div className="p-4">{/* Content here */}</div>
    <DrawerFooter>
      <Button>Submit</Button>
      <DrawerClose render={<Button variant="outline" />}>Cancel</DrawerClose>
    </DrawerFooter>
  </DrawerContent>
</Drawer>

Examples

Position

Use the swipeDirection prop to set the side of the drawer.

PositionSource
Example requirements

Also uses: Button.

Swipe Handle

Use showSwipeHandle on Drawer to render a swipe handle.

Swipe HandleSource
Example requirements

Also uses: Button.

Nested

Open drawers from inside another drawer. Parent drawers stay mounted and stack behind the frontmost drawer.

NestedSource
Example requirements

Also uses: Button.

Copy the example’s local helpers and preserve their relative imports: use-media-query.ts.

Snap Points

Use snapPoints to snap a drawer to preset heights. Numbers between 0 and 1 represent fractions of the viewport. Numbers greater than 1 are treated as pixel values. String values support px and rem units. Snap points apply to vertical drawers.

Snap PointsSource
Example requirements

Also uses: Button.

Responsive

You can combine the Dialog and Drawer components to create a responsive dialog. This renders a Dialog component on desktop and a Drawer on mobile.

ResponsiveSource
Example requirements

Also uses: Button, Dialog, Input, Label.

bun add --exact cn@0.4.0

Copy the example’s local helpers and preserve their relative imports: use-media-query.ts.

Reference

See the official Drawer documentation for composition patterns and API details. This page uses the Preact port and examples from the pinned upstream revision.

Component source