Theme
Customize appearance
Components
Sheet
Open a supporting panel from the side of the screen.
View component source ↗Preview
A minimal example to get started.
Installation
Install this component and its dependencies in a project initialized with shadcn.
pnpm dlx shadcn@latest add https://ui.hyunjoon.net/r/sheet.jsonUsage
This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.
import { Button } from "@/components/ui/button";
import {
Sheet,
SheetTrigger,
SheetContent,
SheetHeader,
SheetTitle,
SheetDescription,
SheetClose,
} from "@/components/ui/sheet";
export default function Example() {
return (
<Sheet>
<SheetTrigger render={<Button variant="outline" />}>Open panel</SheetTrigger>
<SheetContent>
<SheetHeader>
<SheetTitle>Project details</SheetTitle>
<SheetDescription>Manage the details of your current project.</SheetDescription>
</SheetHeader>
<div className="p-4">
<SheetClose render={<Button />}>Done</SheetClose>
</div>
</SheetContent>
</Sheet>
);
}
API reference
Derived from the installed component types. Native DOM props are also supported where applicable. A dash means no explicit default is documented. Some props depend on the selected mode.
Sheet
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | undefinedboolean | undefined | — | Whether the dialog is currently open. |
defaultOpen | boolean | undefinedboolean | undefined | false | Whether the dialog is initially open. To render a controlled dialog, use the `open` prop instead. |
modal | boolean | "trap-focus" | undefinedboolean | "trap-focus" | undefined | true | Determines if the dialog enters a modal state when open. - `true`: user interaction is limited to just the dialog: focus is trapped, document page scroll is locked, and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. - `'trap-focus'`: focus is trapped inside the dialog, but document page scroll is not locked and pointer interactions outside of it remain enabled. When `modal` is `true` or `'trap-focus'`, render `<Dialog.Close>` inside `<Dialog.Popup>` so touch screen readers can escape the popup. |
onOpenChange | ((open: boolean, eventDetails: SheetPrimitive.Root.ChangeEventDetails) => void) | undefine…((open: boolean, eventDetails: SheetPrimitive.Root.ChangeEventDetails) => void) | undefined | — | Event handler called when the dialog is opened or closed. |
onOpenChangeComplete | ((open: boolean) => void) | undefined((open: boolean) => void) | undefined | — | Event handler called after any animations complete when the dialog is opened or closed. |
disablePointerDismissal | boolean | undefinedboolean | undefined | false | Determines whether the dialog should close on outside clicks. |
actionsRef | React.RefObject<DialogRootActions | null> | undefinedReact.RefObject<DialogRootActions | null> | undefined | — | A ref to imperative actions. - `unmount`: When specified, the dialog will not be unmounted when closed. Instead, the `unmount` function must be called to unmount the dialog manually. Useful when the dialog's animation is controlled by an external library. - `close`: Closes the dialog imperatively when called. |
handle | SheetPrimitive.Handle<unknown> | undefinedSheetPrimitive.Handle<unknown> | undefined | — | A handle to associate the dialog with a trigger. If specified, allows external triggers to control the dialog's open state. Can be created with the Dialog.createHandle() method. |
children | React.ReactNode | PayloadChildRenderFunction<unknown>React.ReactNode | PayloadChildRenderFunction<unknown> | — | The content of the dialog. This can be a regular React node or a render function that receives the `payload` of the active trigger. |
triggerId | string | null | undefinedstring | null | undefined | — | ID of the trigger that the dialog is associated with. This is useful in conjunction with the `open` prop to create a controlled dialog. There's no need to specify this prop when the popover is uncontrolled (that is, when the `open` prop is not set). |
defaultTriggerId | string | null | undefinedstring | null | undefined | — | ID of the trigger that the dialog is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open dialog. |
SheetTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
handle | SheetPrimitive.Handle<unknown> | undefinedSheetPrimitive.Handle<unknown> | undefined | — | A handle to associate the trigger with a dialog. Can be created with the Dialog.createHandle() method. |
payload | unknownunknown | — | A payload to pass to the dialog when it is opened. |
id | string | undefinedstring | undefined | — | ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the dialogs in controlled mode (with the DialogRoot `triggerId` prop). |
nativeButton | boolean | undefinedboolean | undefined | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
ref | React.Ref<HTMLButtonElement> | undefinedReact.Ref<HTMLButtonElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLButtonElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLButtonElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLButtonElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLButtonElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLButtonElement, MouseEvent>>) => void) | undefine…((event: BaseUIEvent<React.MouseEvent<HTMLButtonElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
disabled | boolean | undefinedboolean | undefined | — | Prevents user interaction. |
name | string | undefinedstring | undefined | — | Field name used in form data. |
type | "button" | "submit" | "reset" | undefined"button" | "submit" | "reset" | undefined | — | The native input or button behavior. |
value | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | The current value when controlled by the application. |
className | string | ((state: DialogTriggerState) => string | undefined) | undefinedstring | ((state: DialogTriggerState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DialogTriggerState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: DialogTriggerState) => React.CSSProperties | undefined) | u…React.CSSProperties | ((state: DialogTriggerState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
SheetClose
| Prop | Type | Default | Description |
|---|---|---|---|
nativeButton | boolean | undefinedboolean | undefined | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
ref | React.Ref<HTMLButtonElement> | undefinedReact.Ref<HTMLButtonElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLButtonElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLButtonElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLButtonElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLButtonElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLButtonElement, MouseEvent>>) => void) | undefine…((event: BaseUIEvent<React.MouseEvent<HTMLButtonElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
disabled | boolean | undefinedboolean | undefined | — | Prevents user interaction. |
name | string | undefinedstring | undefined | — | Field name used in form data. |
type | "button" | "submit" | "reset" | undefined"button" | "submit" | "reset" | undefined | — | The native input or button behavior. |
value | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | The current value when controlled by the application. |
className | string | ((state: DialogCloseState) => string | undefined) | undefinedstring | ((state: DialogCloseState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DialogCloseState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: DialogCloseState) => React.CSSProperties | undefined) | und…React.CSSProperties | ((state: DialogCloseState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
SheetContent
| Prop | Type | Default | Description |
|---|---|---|---|
initialFocus | boolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | …boolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void) | undefined | — | Determines the element to focus when the dialog is opened. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (first tabbable element or popup). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing. |
finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean |…boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void) | undefined | — | Determines the element to focus when the dialog is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: DialogPopupState) => string | undefined) | undefinedstring | ((state: DialogPopupState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DialogPopupState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: DialogPopupState) => React.CSSProperties | undefined) | und…React.CSSProperties | ((state: DialogPopupState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
side | "top" | "bottom" | "left" | "right" | undefined"top" | "bottom" | "left" | "right" | undefined | "right" | Preferred edge of the anchor for the popup. |
showCloseButton | boolean | undefinedboolean | undefined | true | Displays the popup's close button. |
SheetHeader
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLDivElement> | undefinedReact.FocusEventHandler<HTMLDivElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLDivElement> | undefinedReact.FocusEventHandler<HTMLDivElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLDivElement, Element> | undefinedReact.ChangeEventHandler<HTMLDivElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLDivElement> | undefinedReact.KeyboardEventHandler<HTMLDivElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLDivElement> | undefinedReact.MouseEventHandler<HTMLDivElement> | undefined | — | Called when the element is activated. |
SheetFooter
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLDivElement> | undefinedReact.FocusEventHandler<HTMLDivElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLDivElement> | undefinedReact.FocusEventHandler<HTMLDivElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLDivElement, Element> | undefinedReact.ChangeEventHandler<HTMLDivElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLDivElement> | undefinedReact.KeyboardEventHandler<HTMLDivElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLDivElement> | undefinedReact.MouseEventHandler<HTMLDivElement> | undefined | — | Called when the element is activated. |
SheetTitle
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLHeadingElement> | undefinedReact.Ref<HTMLHeadingElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLHeadingElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLHeadingElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLHeadingElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLHeadingElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLHeadingElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLHeadingElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLHeadingElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLHeadingElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLHeadingElement, MouseEvent>>) => void) | undefin…((event: BaseUIEvent<React.MouseEvent<HTMLHeadingElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: DialogTitleState) => string | undefined) | undefinedstring | ((state: DialogTitleState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DialogTitleState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: DialogTitleState) => React.CSSProperties | undefined) | und…React.CSSProperties | ((state: DialogTitleState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
SheetDescription
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLParagraphElement> | undefinedReact.Ref<HTMLParagraphElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLParagraphElement, Element>>) => void) | undefine…((event: BaseUIEvent<React.FocusEvent<HTMLParagraphElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLParagraphElement, Element>>) => void) | undefine…((event: BaseUIEvent<React.FocusEvent<HTMLParagraphElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLParagraphElement, Element>>) => void) | undefin…((event: BaseUIEvent<React.ChangeEvent<HTMLParagraphElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLParagraphElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLParagraphElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLParagraphElement, MouseEvent>>) => void) | undef…((event: BaseUIEvent<React.MouseEvent<HTMLParagraphElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: DialogDescriptionState) => string | undefined) | undefinedstring | ((state: DialogDescriptionState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DialogDescriptionState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: DialogDescriptionState) => React.CSSProperties | undefined)…React.CSSProperties | ((state: DialogDescriptionState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
Usage notes
Include a title and description and provide a way to close it. Use a dialog for a centered task that should dominate the page.