GooseUI

Components

Drawer

New

A panel that slides up from the bottom edge, common on mobile. It is a native modal dialog: the trigger is a button with Invoker Commands, closedby=any gives Escape and a click on the backdrop, and the top layer, inert page content and focus return come from the browser. A small client script adds the swipe down on the handle and the header and wires the buttons in browsers without Invoker Commands or closedby.

Browser Support

Limited availability
5 features
Details
<dialog>

Opens the modal in the top layer with a backdrop and Escape to close.

Your browser:
Invoker commands

Opens and closes the drawer from buttons without JavaScript. Without it a small script does the same.

Your browser:
<dialog closedby>

Closes the drawer on a click on the backdrop natively. Without it a small script handles the click.

Your browser:
@starting-style

Slides the drawer in when it opens. Without it the drawer appears at once.

Your browser:
transition-behavior

Slides the drawer out when it closes. Without it the drawer disappears at once.

Your browser:

Preview

Move goal

Set your daily activity goal.

Installation

npx shadcn@latest add @gooseui/drawer
pnpm dlx shadcn@latest add @gooseui/drawer
yarn dlx shadcn@latest add @gooseui/drawer
bunx --bun shadcn@latest add @gooseui/drawer

Usage

import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"

export default function Example() {
  return (
    <Drawer>
      <DrawerTrigger asChild>
        <Button variant="outline">Open drawer</Button>
      </DrawerTrigger>
      <DrawerContent>
        <DrawerHeader>
          <DrawerTitle>Move goal</DrawerTitle>
          <DrawerDescription>Set your daily activity goal.</DrawerDescription>
        </DrawerHeader>
        <DrawerFooter>
          <DrawerClose asChild>
            <Button>Submit</Button>
          </DrawerClose>
        </DrawerFooter>
      </DrawerContent>
    </Drawer>
  )
}

Examples

Long content

The drawer is at most 85% of the screen height and scrolls inside. The swipe starts on the handle or the header, so scrolling the content never closes it.

Terms of service

By using the service you agree to these terms. We may update them from time to time and will tell you about important changes by email. You can stop using the service at any time and ask us to delete your data.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.

Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet.

Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur. Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae.

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident.

Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.

<DrawerContent className="mx-auto sm:max-w-md">
  <DrawerHeader>…</DrawerHeader>
  <div className="px-4">Long content scrolls inside</div>
  <DrawerFooter>…</DrawerFooter>
</DrawerContent>

Without a handle

showHandle={false} hides the grab handle. The swipe still works on DrawerHeader.

Share project

Anyone with the link can view the project.

<DrawerContent showHandle={false}>…</DrawerContent>

Props

PropTypeDefaultDescription
openboolean-Controlled open state. Client components only
defaultOpenbooleanfalseOpen right after hydration
onOpenChange(open: boolean) => void-Called with the new state on every open and close. Client components only: functions cannot cross the server boundary
idstring-id of the dialog element. Generated when omitted
asChildbooleanfalseMerge the props into the only child, for example a Button (DrawerTrigger, DrawerClose)
showHandlebooleantrueShow the grab handle at the top (DrawerContent). The swipe works on the handle and on DrawerHeader
classNamestring-Additional CSS classes

Features

  • A native modal dialog with closedby="any": Escape and a click on the backdrop close it.
  • Swipe down on the handle or the header closes it when pulled far enough or fast enough; otherwise it springs back.
  • Labelled by DrawerTitle and described by DrawerDescription; focus returns to the trigger on close.
  • The page behind the drawer is inert and does not scroll.
  • Parts are linked without React context, so Drawer and its parts stay server components. A part rendered inside your own component is not reached: keep the parts in the JSX passed to Drawer.