Drawer
A modal panel that slides against an edge of the screen and closes on Escape, overlay click or an explicit close control.
A panel against an edge of the screen, built on Radix Dialog in React and Reka UI Dialog in Vue. The primitive owns the behaviour; newt/ui owns the look.
Use it to show or edit the details of something while the page it came from stays in view: a member’s profile from the member list, a filter panel, a settings form. When the content is short and needs a decision, use a Modal.
newt-drawerimport { Button } from "@/registry/bases/newt/ui/button"
import {
Drawer,
DrawerBody,
DrawerClose,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/registry/bases/newt/ui/drawer"
export default function DrawerDemo() {
return (
<Drawer>
<DrawerTrigger asChild>
<Button variant="secondary">Open member details</Button>
</DrawerTrigger>
<DrawerContent aria-describedby={undefined}>
<DrawerHeader>
<DrawerTitle>Member details</DrawerTitle>
</DrawerHeader>
<DrawerBody>
Joined 14 March. Three roles, no warnings on record.
</DrawerBody>
<DrawerFooter>
<DrawerClose asChild>
<Button variant="secondary">Close</Button>
</DrawerClose>
<DrawerClose asChild>
<Button>Edit roles</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
)
}<script setup lang="ts">
import { Button } from "~~/registry/bases/newt/ui/button"
import {
Drawer,
DrawerBody,
DrawerClose,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "~~/registry/bases/newt/ui/drawer"
</script>
<template>
<Drawer>
<DrawerTrigger as-child>
<Button variant="secondary">Open member details</Button>
</DrawerTrigger>
<DrawerContent :aria-describedby="undefined">
<DrawerHeader>
<DrawerTitle>Member details</DrawerTitle>
</DrawerHeader>
<DrawerBody>
Joined 14 March. Three roles, no warnings on record.
</DrawerBody>
<DrawerFooter>
<DrawerClose as-child>
<Button variant="secondary">Close</Button>
</DrawerClose>
<DrawerClose as-child>
<Button>Edit roles</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
</template>Installation
npx newtui@latest add drawernpx shadcn@latest add @newtui/drawernpx shadcn-vue@latest add @newtui/drawerpnpm dlx newtui@latest add drawerpnpm dlx shadcn@latest add @newtui/drawerpnpm dlx shadcn-vue@latest add @newtui/draweryarn dlx newtui@latest add draweryarn dlx shadcn@latest add @newtui/draweryarn dlx shadcn-vue@latest add @newtui/drawerbunx newtui@latest add drawerbunx shadcn@latest add @newtui/drawerbunx shadcn-vue@latest add @newtui/drawerdeno run -A npm:newtui@latest add drawerdeno run -A npm:shadcn@latest add @newtui/drawerdeno run -A npm:shadcn-vue@latest add @newtui/drawervlx newtui@latest add drawervlx shadcn@latest add @newtui/drawervlx shadcn-vue@latest add @newtui/drawervp dlx newtui@latest add drawervp dlx shadcn@latest add @newtui/drawervp dlx shadcn-vue@latest add @newtui/drawernubx newtui@latest add drawernubx shadcn@latest add @newtui/drawernubx shadcn-vue@latest add @newtui/drawernlx newtui@latest add drawernlx shadcn@latest add @newtui/drawernlx shadcn-vue@latest add @newtui/drawerupx newtui@latest add drawerupx shadcn@latest add @newtui/drawerupx shadcn-vue@latest add @newtui/drawer- newtui
- shadcn
- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
The shadcn CLI needs the @newtui registry in your components.json. Set it up.
Install the dependencies
npm install radix-uipnpm add radix-uiyarn add radix-uibun add radix-uideno add npm:radix-uivlt install radix-uivp add radix-uinub add radix-uini radix-uiupm add radix-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
npm install reka-uipnpm add reka-uiyarn add reka-uibun add reka-uideno add npm:reka-uivlt install reka-uivp add reka-uinub add reka-uini reka-uiupm add reka-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
Copy the source into your project
"use client"
import { Dialog as DialogPrimitive } from "radix-ui"
import * as React from "react"
import { cn } from "@/lib/utils"
/*
* A panel that comes in from the edge and keeps the page behind it in view.
* Radix owns the behaviour: open state, the focus trap, Escape and outside
* press, scroll lock, hiding the page from screen readers, and giving focus
* back to the trigger. Only the look is newt/ui's.
*/
const Drawer = DialogPrimitive.Root
/*
* It has no look of its own. Pass `asChild` to put the state on your own
* button: `<DrawerTrigger asChild><Button>Open</Button></DrawerTrigger>`.
* Focus returns to the trigger when the drawer closes. A drawer opened from
* state alone has no trigger, so pass `onCloseAutoFocus` to `DrawerContent`
* to say where focus goes.
*/
const DrawerTrigger = DialogPrimitive.Trigger
/**
* Closes the drawer when activated. Wrap a Button with `asChild` to keep its styling:
* `<DrawerClose asChild><Button variant="secondary">Cancel</Button></DrawerClose>`
*/
const DrawerClose = DialogPrimitive.Close
const SIDE = {
end: "inset-y-0 end-0 start-auto h-full w-[380px] max-w-[90vw] border-s",
start: "inset-y-0 start-0 end-auto h-full w-[380px] max-w-[90vw] border-e",
bottom:
"inset-x-0 bottom-0 top-auto h-auto max-h-[85vh] w-full max-w-none border-t",
} as const
const DrawerContent = React.forwardRef<
React.ComponentRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
/** The edge it sits against. `end` is the right in left-to-right text. */
side?: keyof typeof SIDE
/**
* The element the overlay and panel are portalled into. Defaults to
* `document.body`. A drawer opened below a `DirectionProvider` or a themed
* wrapper passes that element, so it keeps the direction and the palette.
*/
container?: React.ComponentProps<typeof DialogPrimitive.Portal>["container"]
}
>(({ className, children, side = "end", container, ...props }, ref) => (
<DialogPrimitive.Portal container={container}>
<DialogPrimitive.Overlay className="fixed inset-0 z-[100] bg-newt-overlay" />
<DialogPrimitive.Content
ref={ref}
data-side={side}
className={cn(
"fixed z-[100] flex flex-col border-newt-border bg-newt-bg-elevated text-newt-text-primary shadow-elevation-high outline-none",
SIDE[side],
className
)}
{...props}
>
{children}
</DialogPrimitive.Content>
</DialogPrimitive.Portal>
))
DrawerContent.displayName = "DrawerContent"
export interface DrawerHeaderProps extends React.ComponentProps<"header"> {
/** Accessible name of the close button. */
closeLabel?: string
}
/** The row for `DrawerTitle`, with the button that closes the drawer at its end. */
const DrawerHeader = React.forwardRef<HTMLElement, DrawerHeaderProps>(
({ className, closeLabel = "Close", children, ...props }, ref) => (
<header
ref={ref}
className={cn(
"flex items-center justify-between gap-3 border-b border-newt-border p-4",
className
)}
{...props}
>
<div className="flex min-w-0 flex-col gap-1">{children}</div>
<DialogPrimitive.Close
aria-label={closeLabel}
className="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--newt-radius-sm)] text-newt-text-muted hover:bg-newt-bg-hover hover:text-newt-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link"
>
<svg viewBox="0 0 16 16" aria-hidden="true" className="h-4 w-4">
<path
fill="currentColor"
d="M4.3 4.3a1 1 0 0 1 1.4 0L8 6.6l2.3-2.3a1 1 0 1 1 1.4 1.4L9.4 8l2.3 2.3a1 1 0 0 1-1.4 1.4L8 9.4l-2.3 2.3a1 1 0 0 1-1.4-1.4L6.6 8 4.3 5.7a1 1 0 0 1 0-1.4Z"
/>
</svg>
</DialogPrimitive.Close>
</header>
)
)
DrawerHeader.displayName = "DrawerHeader"
/** The dialog's accessible name. Give it real text. */
const DrawerTitle = React.forwardRef<
React.ComponentRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn("m-0 text-base font-semibold leading-5", className)}
{...props}
/>
))
DrawerTitle.displayName = "DrawerTitle"
/**
* Radix links it to the dialog with `aria-describedby`. A drawer without one
* passes `aria-describedby={undefined}` to `DrawerContent` to say so.
*/
const DrawerDescription = React.forwardRef<
React.ComponentRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("m-0 text-sm leading-5 text-newt-text-secondary", className)}
{...props}
/>
))
DrawerDescription.displayName = "DrawerDescription"
const DrawerBody = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div">
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"flex-1 overflow-y-auto p-4 text-sm leading-5 text-newt-text-secondary",
className
)}
{...props}
/>
))
DrawerBody.displayName = "DrawerBody"
const DrawerFooter = React.forwardRef<
HTMLElement,
React.ComponentProps<"footer">
>(({ className, ...props }, ref) => (
<footer
ref={ref}
className={cn("flex justify-end gap-2 bg-newt-bg-surface p-4", className)}
{...props}
/>
))
DrawerFooter.displayName = "DrawerFooter"
export {
Drawer,
DrawerTrigger,
DrawerContent,
DrawerHeader,
DrawerTitle,
DrawerDescription,
DrawerBody,
DrawerFooter,
DrawerClose,
}<script setup lang="ts">
import {
DialogRoot,
useForwardPropsEmits,
type DialogRootEmits,
type DialogRootProps,
} from "reka-ui"
/*
* Reka owns the behaviour: open state, the focus trap, Escape and outside
* press, scroll lock, hiding the page from screen readers, and giving focus
* back to the trigger. Use `v-model:open` to control it. Only the look is
* newt/ui's.
*/
const props = defineProps<DialogRootProps>()
const emits = defineEmits<DialogRootEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>
<template>
<DialogRoot v-bind="forwarded">
<slot />
</DialogRoot>
</template><script setup lang="ts">
import { DialogTrigger, type DialogTriggerProps } from "reka-ui"
/*
* It has no look of its own. Pass `as-child` to put the state on your own
* button: `<DrawerTrigger as-child><Button>Open</Button></DrawerTrigger>`.
* Focus returns to the trigger when the drawer closes. A drawer opened from
* state alone has no trigger, so handle `@close-auto-focus` on `DrawerContent`
* to say where focus goes.
*/
const props = defineProps<DialogTriggerProps>()
</script>
<template>
<DialogTrigger v-bind="props">
<slot />
</DialogTrigger>
</template><script setup lang="ts">
import {
DialogContent,
DialogOverlay,
DialogPortal,
useForwardPropsEmits,
type DialogContentEmits,
type DialogContentProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
defineOptions({ inheritAttrs: false })
const props = withDefaults(
defineProps<
DialogContentProps & {
class?: HTMLAttributes["class"]
/** The edge it sits against. `end` is the right in left-to-right text. */
side?: "end" | "start" | "bottom"
/**
* The element the overlay and panel are portalled into. Defaults to
* `body`. A drawer opened below a `DirectionProvider` or a themed
* wrapper passes that element, so it keeps the direction and the palette.
*/
container?: string | HTMLElement
}
>(),
{ side: "end" }
)
const emits = defineEmits<DialogContentEmits>()
const SIDE = {
end: "inset-y-0 end-0 start-auto h-full w-[380px] max-w-[90vw] border-s",
start: "inset-y-0 start-0 end-auto h-full w-[380px] max-w-[90vw] border-e",
bottom:
"inset-x-0 bottom-0 top-auto h-auto max-h-[85vh] w-full max-w-none border-t",
} as const
const delegated = computed(() => {
const { class: _class, side: _side, container: _container, ...rest } = props
return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)
</script>
<template>
<DialogPortal :to="props.container">
<DialogOverlay class="fixed inset-0 z-[100] bg-newt-overlay" />
<DialogContent
v-bind="{ ...forwarded, ...$attrs }"
:data-side="props.side"
:class="
cn(
'fixed z-[100] flex flex-col border-newt-border bg-newt-bg-elevated text-newt-text-primary shadow-elevation-high outline-none',
SIDE[props.side],
props.class
)
"
>
<slot />
</DialogContent>
</DialogPortal>
</template><script setup lang="ts">
import { DialogClose } from "reka-ui"
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
/* The row for `DrawerTitle`, with the button that closes the drawer at its end. */
const props = withDefaults(
defineProps<{
class?: HTMLAttributes["class"]
/** Accessible name of the close button. */
closeLabel?: string
}>(),
{ closeLabel: "Close" }
)
</script>
<template>
<header
:class="
cn(
'flex items-center justify-between gap-3 border-b border-newt-border p-4',
props.class
)
"
>
<div class="flex min-w-0 flex-col gap-1">
<slot />
</div>
<DialogClose
:aria-label="props.closeLabel"
class="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--newt-radius-sm)] text-newt-text-muted hover:bg-newt-bg-hover hover:text-newt-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link"
>
<svg viewBox="0 0 16 16" aria-hidden="true" class="h-4 w-4">
<path
fill="currentColor"
d="M4.3 4.3a1 1 0 0 1 1.4 0L8 6.6l2.3-2.3a1 1 0 1 1 1.4 1.4L9.4 8l2.3 2.3a1 1 0 0 1-1.4 1.4L8 9.4l-2.3 2.3a1 1 0 0 1-1.4-1.4L6.6 8 4.3 5.7a1 1 0 0 1 0-1.4Z"
/>
</svg>
</DialogClose>
</header>
</template><script setup lang="ts">
import { DialogTitle, type DialogTitleProps } from "reka-ui"
import { computed, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
/* The dialog's accessible name. Give it real text. */
const props = defineProps<
DialogTitleProps & { class?: HTMLAttributes["class"] }
>()
const delegated = computed(() => {
const { class: _class, ...rest } = props
return rest
})
</script>
<template>
<DialogTitle
v-bind="delegated"
:class="cn('m-0 text-base font-semibold leading-5', props.class)"
>
<slot />
</DialogTitle>
</template><script setup lang="ts">
import { DialogDescription, type DialogDescriptionProps } from "reka-ui"
import { computed, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
/*
* Reka links it to the dialog with `aria-describedby`. A drawer without one
* passes `:aria-describedby="undefined"` to `DrawerContent` to say so.
*/
const props = defineProps<
DialogDescriptionProps & { class?: HTMLAttributes["class"] }
>()
const delegated = computed(() => {
const { class: _class, ...rest } = props
return rest
})
</script>
<template>
<DialogDescription
v-bind="delegated"
:class="cn('m-0 text-sm leading-5 text-newt-text-secondary', props.class)"
>
<slot />
</DialogDescription>
</template><script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>
<template>
<div
:class="
cn(
'flex-1 overflow-y-auto p-4 text-sm leading-5 text-newt-text-secondary',
props.class
)
"
>
<slot />
</div>
</template><script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const props = defineProps<{ class?: HTMLAttributes["class"] }>()
</script>
<template>
<footer
:class="cn('flex justify-end gap-2 bg-newt-bg-surface p-4', props.class)"
>
<slot />
</footer>
</template><script setup lang="ts">
import { DialogClose, type DialogCloseProps } from "reka-ui"
/*
* Closes the drawer when activated. Wrap a Button with `as-child` to keep its
* styling: `<DrawerClose as-child><Button variant="secondary">Cancel</Button></DrawerClose>`
*/
const props = defineProps<DialogCloseProps>()
</script>
<template>
<DialogClose v-bind="props">
<slot />
</DialogClose>
</template>export { default as Drawer } from "./Drawer.vue"
export { default as DrawerTrigger } from "./DrawerTrigger.vue"
export { default as DrawerContent } from "./DrawerContent.vue"
export { default as DrawerHeader } from "./DrawerHeader.vue"
export { default as DrawerTitle } from "./DrawerTitle.vue"
export { default as DrawerDescription } from "./DrawerDescription.vue"
export { default as DrawerBody } from "./DrawerBody.vue"
export { default as DrawerFooter } from "./DrawerFooter.vue"
export { default as DrawerClose } from "./DrawerClose.vue"Update the import paths
The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Drawer to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Drawer to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
Usage
import { Drawer } from "@/components/ui/drawer"
export function Example() {
return <Drawer />
}<script setup lang="ts">
import { Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerTitle, DrawerDescription, DrawerBody, DrawerFooter, DrawerClose } from "@/components/ui/drawer"
</script>
<template>
<Drawer />
</template>Put DrawerTrigger and DrawerContent inside Drawer. DrawerContent holds a DrawerHeader with a DrawerTitle, then a DrawerBody, then an optional DrawerFooter. DrawerBody scrolls when the content is taller than the screen. The header and the footer stay in place.
API reference
Drawer
open / v-model:open?boolean
Whether the drawer is shown. Leave it out and pass `defaultOpen` to let the drawer own it.
booleanonOpenChange?(open: boolean) => void
React only. Called when the drawer asks to open or close; Vue emits `update:open`.
(open: boolean) => voidDrawerContent
side?"end" | "start" | "bottom"
The edge it sits against. `end` is the right in left-to-right text and the left in right-to-left.
"end" | "start" | "bottom""end"onCloseAutoFocus?(event: Event) => void
Called when focus is about to return to the trigger. Call `event.preventDefault()` and focus an element yourself when the drawer opened without a `DrawerTrigger`. Vue emits `close-auto-focus`.
(event: Event) => voidaria-describedby?string | undefined
Pass `undefined` when the drawer has no `DrawerDescription`.
string | undefinedcontainer?HTMLElement
Element the overlay and panel are portalled into. A drawer below a `DirectionProvider` or a themed wrapper passes that element to keep the direction and the palette.
HTMLElementdocument.bodyDrawerHeader
closeLabel?string
Accessible name of the close button in the header.
string"Close"DrawerTrigger and DrawerClose render a button. Pass asChild (as-child in Vue) to put the behaviour on your own element, such as a Button. DrawerTitle and DrawerDescription go inside DrawerHeader. Every part also accepts the native attributes of the element it renders, and a className that is merged rather than replaced.
Accessibility
The panel carries role="dialog" and aria-modal="true", and closes on Escape or a press on the dimmed page. DrawerTitle is its accessible name, so always render one with real text. DrawerDescription is its accessible description. When the drawer opens, focus moves to its first control. While it is open, Tab and Shift+Tab stay inside the panel, and the primitive hides the page behind from screen readers. When it closes, focus goes back to the DrawerTrigger. The close button in the header has a visible focus ring and takes its name from closeLabel. Use side="bottom" on a phone, where a side panel would cover the whole screen.
closeLabel on DrawerHeader names the close button; it defaults to Close. Translating labels lists every English default.
Tokens
Drawer reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-drawer.
--newt-border--newt-bg-elevated--newt-shadow-elevation-high--newt-text-primary--newt-radius-sm--newt-text-muted--newt-bg-hover--newt-text-link--newt-text-secondary--newt-bg-surface