Theme
Customize appearance
Components
Dialog
Focus attention on a task in a modal window.
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/dialog.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 {
Dialog,
DialogTrigger,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
export default function Example() {
return (
<Dialog>
<DialogTrigger render={<Button variant="outline" />}>Edit profile</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Your profile</DialogTitle>
<DialogDescription>Update how your name appears to teammates.</DialogDescription>
</DialogHeader>
<label className="grid gap-2 text-sm">
Display name
<Input defaultValue="Alex Jordan" />
</label>
<DialogFooter>
<DialogClose render={<Button />}>Done</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
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.
Dialog
| 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: DialogPrimitive.Root.ChangeEventDetails) => void) | undefin…((open: boolean, eventDetails: DialogPrimitive.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 | DialogPrimitive.Handle<unknown> | undefinedDialogPrimitive.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. |
DialogClose
| 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. |
DialogContent
| 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. |
showCloseButton | boolean | undefinedboolean | undefined | true | Displays the popup's close button. |
DialogDescription
| 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. |
DialogFooter
| 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. |
showCloseButton | boolean | undefinedboolean | undefined | false | Displays the popup's close button. |
DialogHeader
| 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. |
DialogOverlay
| Prop | Type | Default | Description |
|---|---|---|---|
forceRender | boolean | undefinedboolean | undefined | false | Whether the backdrop is forced to render even when nested. |
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: DialogBackdropState) => string | undefined) | undefinedstring | ((state: DialogBackdropState) => 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, DialogBackdropState> | 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: DialogBackdropState) => React.CSSProperties | undefined) | …React.CSSProperties | ((state: DialogBackdropState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
DialogPortal
| Prop | Type | Default | Description |
|---|---|---|---|
keepMounted | boolean | undefinedboolean | undefined | false | Whether to keep the portal mounted in the DOM while the popup is hidden. |
container | HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undef…HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undefined | — | A parent element to render the portal element into. |
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: DialogPortalState) => string | undefined) | undefinedstring | ((state: DialogPortalState) => 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, DialogPortalState> | 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: DialogPortalState) => React.CSSProperties | undefined) | un…React.CSSProperties | ((state: DialogPortalState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
DialogTitle
| 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. |
DialogTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
handle | DialogPrimitive.Handle<unknown> | undefinedDialogPrimitive.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. |
Usage notes
Include a title and description for context. Use render to compose the trigger with a Button, and close the dialog after completing the task.