Skip to content

Dialog

The Dialog component provides an accessible and customizable dialog overlay for displaying important content or requesting user input. It supports different sizes, themes, and can include an icon or logo in the header.

Variations

Sizes

The Dialog component offers four size options: sm, md, lg, and max (which sets the dialog to 80% of the viewport’s width and height).

Themes

Headers can have themes default, warning and danger with matching icons:

Logo and icon

Headers can display a logo or an icon:

Hidden close button

You can hide the close button in the top-right corner using the hideClose prop:

Scrollable content

The Body component automatically handles scrolling for long content:

Custom trigger focus

If a dialog is opened without the Trigger component (e.g., a dropdown item), focus will not return to the trigger element when the dialog is closed. To address this use useCustomDialogTrigger hook to register your custom trigger element.

Installation

import { Dialog } from "@harnessio/ui/components";
// ...
return (
<Dialog.Root>
<Dialog.Trigger>
<Button>Open Dialog</Button>
</Dialog.Trigger>
<Dialog.Content size="md">
<Dialog.Header icon="plus-circle">
<Dialog.Title>Dialog Title</Dialog.Title>
<Dialog.Description>Optional description text</Dialog.Description>
</Dialog.Header>
<Dialog.Body>
Dialog content goes here
</Dialog.Body>
<Dialog.Footer>
<Dialog.Close>Cancel</Dialog.Close>
<Button variant="primary">Confirm</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
)