Ship faster with goilerplate templUI Pro

Dialog

Dialog overlay that requires user attention or interaction.

Source Tailwind CSS JavaScript

Default

Edit Profile

Make changes to your profile here. Click save when you're done.

Installation

templui add dialog

Load the script once in your layout:

<head>
  @dialog.Script()
</head>

Examples

External Trigger

External Dialog

This dialog can be triggered from anywhere on the page.

Standalone Content

Standalone Dialog

This dialog content works without a wrapper component.

Perfect for dynamic content loading with HTMX or similar frameworks.

API Reference

Required parameter
Hover for description

Dialog

Main dialog wrapper component. Provides context for child components.

Name Type Default
ID

Unique identifier for the dialog

string
randomID
Class

Additional CSS classes to apply to the dialog container

string
""
Attributes

Additional HTML attributes to apply to the dialog container

templ.Attributes
nil
DisableClickAway

Whether to disable closing the dialog by clicking outside

bool
false
DisableESC

Whether to disable closing the dialog with the ESC key

bool
false
Open

Whether the dialog should be open initially

bool
false

Trigger

Element that triggers the dialog to open. Can be used inside Dialog wrapper or externally with For prop.

Name Type Default
ID

Unique identifier for the trigger element

string
""
Class

Additional CSS classes to apply to the trigger

string
""
Attributes

Additional HTML attributes to apply to the trigger

templ.Attributes
nil
For

ID of a specific dialog to trigger (for external triggers)

string
""

Content

Dialog content container. Can be used standalone for HTMX or inside Dialog wrapper.

Name Type Default
ID

Dialog ID for standalone usage (when no context)

string
""
Class

Additional CSS classes to apply to the content

string
""
Attributes

Additional HTML attributes to apply to the content

templ.Attributes
nil
HideCloseButton

Whether to hide the default close button

bool
false
Open

Initial open state for standalone usage

bool
false
DisableAutoFocus

Whether to disable automatic focusing of the first focusable element

bool
false

Title

Dialog title component. Should be used inside Header.

Name Type Default
ID

Unique identifier for the title element

string
""
Class

Additional CSS classes to apply to the title

string
""
Attributes

Additional HTML attributes to apply to the title

templ.Attributes
nil

Description

Dialog description component. Should be used inside Header.

Name Type Default
ID

Unique identifier for the description element

string
""
Class

Additional CSS classes to apply to the description

string
""
Attributes

Additional HTML attributes to apply to the description

templ.Attributes
nil

Body

Body/content section of the dialog.

Name Type Default
ID

Unique identifier for the body element

string
""
Class

Additional CSS classes to apply to the body

string
""
Attributes

Additional HTML attributes to apply to the body

templ.Attributes
nil

Close

Element that closes the dialog.

Name Type Default
ID

Unique identifier for the close element

string
""
Class

Additional CSS classes to apply to the close element

string
""
Attributes

Additional HTML attributes to apply to the close element

templ.Attributes
nil
For

ID of the dialog to close (defaults to closest dialog if empty)

string
""

JavaScript API

// Open a dialog programmatically
window.tui.dialog.open("dialog-id");

// Close a dialog
window.tui.dialog.close("dialog-id");

// Toggle dialog state
window.tui.dialog.toggle("dialog-id");

// Check if dialog is open (returns true/false)
const isOpen = window.tui.dialog.isOpen("dialog-id");