Skip to Content

Dialog

Centered modal dialog built on Radix UI. Supports controlled state, uncontrolled state, trigger elements, and ref-based open/close.

Props

PropTypeDefaultDescription
openbooleanControlled open state
onOpenChange(open: boolean) => voidCalled when open state changes
onClose() => voidCalled when the dialog finishes closing
childrenReactNodeDialog content
triggerReactNodeOptional trigger element that opens the dialog
titlestringDialog title (rendered in header, required for accessibility)
showClosebooleantrueWhether to show the close (X) button
closeOnOverlayClickbooleantrueWhether clicking the overlay closes the dialog
overlayColorstringrgba(0,0,0,0.5)Overlay background color
backgroundColorstring#ffffffDialog panel background color
borderRadiusstring | number16Dialog panel border radius
maxWidthstring | number500Dialog max width
paddingstring | number24Dialog panel padding
classNamestringPanel className
styleCSSPropertiesPanel style

Ref Handle

MethodDescription
open()Open the dialog
close()Close the dialog

Example

const dialogRef = useRef<DialogHandle>(null) <Dialog ref={dialogRef} title="Confirm purchase"> <p>You will be charged $9.99</p> <button onClick={() => dialogRef.current?.close()}>Confirm</button> </Dialog> <button onClick={() => dialogRef.current?.open()}>Buy now</button>

Uncontrolled with a trigger:

<Dialog trigger={<button>Open</button>} title="Settings"> <p>Dialog content here</p> </Dialog>
Last updated on