@biem/ui

Dialog

A window above the page in which users read details or complete a short task.

A dialog opens a window above the page, where users read details or complete a short task without leaving the page. While it is open, focus stays in the dialog and the page behind it doesn't scroll. Users close it with the close button, the Escape key or a press outside the dialog.

Usage

dialog-default.tsx
import { Button } from "@biem/ui/components/ui/button";
import {
	Dialog,
	DialogContent,
	DialogDescription,
	DialogHeader,
	DialogTitle,
	DialogTrigger,
} from "@biem/ui/components/ui/dialog";

export function DialogDefault() {
	return (
		<Dialog>
			<DialogTrigger render={<Button variant="outline"/>}>Transfer details</DialogTrigger>
			<DialogContent>
				<DialogHeader>
					<DialogTitle>Transfer details</DialogTitle>
					<DialogDescription>
						The warehouse ships 12 cases on Monday. The store receives them on Tuesday between 6:00 and 8:00.
					</DialogDescription>
				</DialogHeader>
			</DialogContent>
		</Dialog>
	);
}

Examples

Most tasks in a dialog end with a decision: users either complete the task or step back from it. The footer gathers the actions for that decision, and an action placed in DialogClose lets users leave the dialog without completing the task.

Where a dialog only informs, users need no decision, just a clear way back to the page. Set on the footer, showCloseButton adds a button that closes the dialog, so users return to their work as soon as they have read the content.

Without Close Button

Once the footer offers a way to cancel, a separate close button only repeats it. With showCloseButton set to false, DialogContent leaves that button out, and the decision rests with the actions of the footer. The Escape key and a press outside the dialog still close it.

Controlled

In some workflows the application decides when a dialog opens or closes, for example to close it as soon as the task that users started has finished. Through open and onOpenChange it holds the open state, so any action in the dialog can close it, and other parts of the interface can open it.

Disabled Trigger

Until the data that a dialog shows has loaded, opening it would leave users with an empty window. Marked as disabled, the trigger no longer opens the dialog, and users still see the action that will soon be available.

Disabled Close

While a dialog saves its input, an action that would discard that input has to wait. Set on DialogClose, disabled stops only that button from closing the dialog, and the other ways to close it stay available.

API Reference

Dialog

Propopen
Typeboolean
Default–
DescriptionSets whether the dialog is open and makes it controlled. Update it in onOpenChange.
PropdefaultOpen
Typeboolean
Defaultfalse
DescriptionOpens the dialog at first render. The dialog then tracks its open state itself.
ProponOpenChange
Type(open: boolean, eventDetails: DialogRootChangeEventDetails) => void
Default–
DescriptionRuns when users open or close the dialog. It receives the open state that follows.
ProponOpenChangeComplete
Type(open: boolean) => void
Default–
DescriptionRuns after the dialog has opened or closed and its animations have finished.
Propmodal
Typeboolean | "trap-focus"
Defaulttrue
DescriptionSets how the dialog limits the rest of the page while it is open. With true, focus stays in the dialog and the page doesn't scroll. With "trap-focus", focus stays in the dialog, but the page scrolls. With false, focus can move to the rest of the page, and the page scrolls.
PropdisablePointerDismissal
Typeboolean
Defaultfalse
DescriptionKeeps the dialog open when users press outside of it. A dialog with modal set to false then also stays open when focus moves outside of it.
ProptriggerId
Typestring | null
Default–
DescriptionSets the ID of the trigger that a controlled dialog is associated with. A dialog without open doesn't need it.
PropdefaultTriggerId
Typestring | null
Default–
DescriptionSets the ID of the trigger that the dialog is associated with when defaultOpen opens it at first render.
Prophandle
TypeDialogHandle<Payload>
Default–
DescriptionConnects the dialog with triggers that are rendered outside of it. Create the handle with Dialog.createHandle() from @base-ui/react/dialog.
PropactionsRef
TypeRefObject<DialogRootActions | null>
Default–
DescriptionReceives the functions close and unmount. close closes the dialog from code, and unmount removes it from the DOM after a closing animation that the code controls itself.
Propchildren
TypeReactNode | ((arg: { payload: Payload | undefined }) => ReactNode)
Default–
DescriptionHolds the parts of the dialog. A function receives the payload of the trigger that opened the dialog.

DialogTrigger

Prophandle
TypeDialogHandle<Payload>
Default–
DescriptionConnects the trigger with a dialog that it is rendered outside of. Pass the same handle to Dialog.
Proppayload
TypePayload
Default–
DescriptionPasses a value to the dialog when this trigger opens it. A function as children of Dialog receives it.
Propid
Typestring
Default–
DescriptionSets the ID of the trigger element. triggerId and defaultTriggerId of Dialog refer to it.
Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the trigger with another component.
PropnativeButton
Typeboolean
Defaulttrue
DescriptionDeclares whether the rendered element is a native button. Set it to false when render returns a different element.
Propdisabled
Typeboolean
Defaultfalse
DescriptionPrevents users from opening the dialog with this trigger.

DialogPortal

PropkeepMounted
Typeboolean
Defaultfalse
DescriptionKeeps the portal in the DOM while the dialog is closed.
Propcontainer
TypeHTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null
Default–
DescriptionSets the element that the portal is rendered into. Without it, the portal is appended to the body.
Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the portal with another component.

DialogOverlay

PropforceRender
Typeboolean
Defaultfalse
DescriptionRenders the overlay even when the dialog is nested in another dialog.
Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the overlay with another component.

DialogContent

PropshowCloseButton
Typeboolean
Defaulttrue
DescriptionShows the close button in the top right corner of the dialog.
PropinitialFocus
Typeboolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void)
Default–
DescriptionDetermines the element that receives focus when the dialog opens. Without it, focus moves to the first focusable element in the dialog.
PropfinalFocus
Typeboolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void)
Default–
DescriptionDetermines the element that receives focus when the dialog closes. Without it, focus returns to the trigger or to the element that had focus before.
Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the content with another component.

DialogHeader

DialogHeader groups the title and the description. It renders a div and has no props of its own.

DialogTitle

Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the title with another component.

DialogDescription

Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the description with another component.

DialogFooter

PropshowCloseButton
Typeboolean
Defaultfalse
DescriptionAdds an outline button with the label "Close" after the children of the footer. It closes the dialog.

DialogClose

Proprender
TypeReactElement | render function
Default–
DescriptionReplaces the native element or composes the close button with another component.
PropnativeButton
Typeboolean
Defaulttrue
DescriptionDeclares whether the rendered element is a native button. Set it to false when render returns a different element.
Propdisabled
Typeboolean
Defaultfalse
DescriptionPrevents users from closing the dialog with this button.