shadcn-templ 2.0 beta. Switch to templUI v1
1.7k

Dialog

A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.

package examples import (

Installation

shadcn-templ add dialog

Usage

import "github.com/axadrn/shadcn-templ/v2/components/dialog"
@dialog.Dialog() {	@button.Button(button.Props{Attributes: dialog.Trigger(ctx)}) {		Open	}	@dialog.Content() {		@dialog.Header() {			@dialog.Title() {				Are you absolutely sure?			}			@dialog.Description() {				This action cannot be undone.			}		}	}}

Composition

Use the following composition to build a Dialog:

dialog.Dialog├── dialog.Trigger└── dialog.Content    ├── dialog.Header    │   ├── dialog.Title    │   └── dialog.Description    └── dialog.Footer        └── dialog.Close

Custom Close Button

Replace the default close control with your own button.

package examples import (

No Close Button

Use HideCloseButton to hide the close button.

package examples import (

Keep actions visible while the content scrolls.

package examples import (

Scrollable Content

Long content can scroll while the header stays in view.

package examples import (

API Reference

Dialog

The Dialog component is the root that links trigger, content and close via context.

Prop Type Default
Open bool false
DisableDismissible bool false

Trigger

dialog.Trigger(ctx) returns the attributes that turn any element into the trigger, usually spread onto a Button. Use dialog.TriggerFor(id) to target a dialog outside the current root.

Prop Type Default
ctx context.Context -

Content

The dialog.Content component is the dialog window.

Prop Type Default
HideCloseButton bool false
DisableModal bool false
Class string -

The dialog.Header component holds the title and description.

Prop Type Default
Class string -

Title

The dialog.Title component is the accessible dialog title.

Prop Type Default
Class string -

Description

The dialog.Description component is the accessible dialog description.

Prop Type Default
Class string -

The dialog.Footer component holds the actions at the bottom of the dialog.

Prop Type Default
Class string -

Close

dialog.Close(ctx) returns the attributes that make any element close the dialog. Use dialog.CloseFor(id) to target a dialog outside the current root.

Prop Type Default
ctx context.Context -