ShellUI Logo
ShellUI

Dialog

Compound modal dialog overlay for displaying content that requires user attention.

Overview

The Dialog component is a compound component that provides a modal overlay for forms, confirmations, and important content. It uses CascadingParameter to share open state between sub-components and Shell.Cn() for class merging.

Installation

shellui add dialog

Usage

Basic Dialog

<Dialog Open="@isOpen" OpenChanged="@((bool v) => isOpen = v)">
  <DialogTrigger>
    <Button>Open Dialog</Button>
  </DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Dialog Title</DialogTitle>
      <DialogDescription>This is a description of the dialog.</DialogDescription>
    </DialogHeader>
    <p>Your content goes here.</p>
    <DialogFooter>
      <DialogClose><Button Variant="ButtonVariant.Outline">Cancel</Button></DialogClose>
      <Button OnClick="HandleSave">Save</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>

@code {
    private bool isOpen = false;
    private void HandleSave() { isOpen = false; }
}

Confirmation Dialog

<Dialog Open="@showConfirm" OpenChanged="@((bool v) => showConfirm = v)">
  <DialogTrigger>
    <Button Variant="ButtonVariant.Destructive">Delete Item</Button>
  </DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Are you sure?</DialogTitle>
      <DialogDescription>This action cannot be undone.</DialogDescription>
    </DialogHeader>
    <DialogFooter>
      <DialogClose><Button Variant="ButtonVariant.Outline">Cancel</Button></DialogClose>
      <Button Variant="ButtonVariant.Destructive" OnClick="HandleDelete">Delete</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>

@code {
    private bool showConfirm = false;
    private void HandleDelete() { showConfirm = false; }
}

Form Dialog

<Dialog Open="@isOpen" OpenChanged="@((bool v) => isOpen = v)">
  <DialogTrigger>
    <Button>Add User</Button>
  </DialogTrigger>
  <DialogContent Class="sm:max-w-[425px]">
    <DialogHeader>
      <DialogTitle>Add New User</DialogTitle>
      <DialogDescription>Enter the user details below.</DialogDescription>
    </DialogHeader>
    <div class="space-y-4 py-4">
      <div class="space-y-2">
        <Label>Name</Label>
        <Input @bind-Value="name" />
      </div>
      <div class="space-y-2">
        <Label>Email</Label>
        <Input @bind-Value="email" Type="email" />
      </div>
    </div>
    <DialogFooter>
      <DialogClose><Button Variant="ButtonVariant.Outline">Cancel</Button></DialogClose>
      <Button OnClick="HandleSubmit">Add User</Button>
    </DialogFooter>
  </DialogContent>
</Dialog>

@code {
    private bool isOpen = false;
    private string name = "";
    private string email = "";
    private void HandleSubmit() { isOpen = false; }
}

API Reference

Dialog

ParameterTypeDefaultDescription
OpenboolfalseControls the dialog open state
OpenChangedEventCallback<bool>Callback when open state changes
ChildContentRenderFragmentDialog sub-components

DialogTrigger

ParameterTypeDefaultDescription
ChildContentRenderFragmentElement that opens the dialog on click

DialogContent

ParameterTypeDefaultDescription
ChildContentRenderFragmentModal body content
Classstring?nullAdditional CSS classes

DialogHeader / DialogFooter

ParameterTypeDefaultDescription
ChildContentRenderFragmentSection content
Classstring?nullAdditional CSS classes

DialogTitle / DialogDescription

ParameterTypeDefaultDescription
ChildContentRenderFragmentText content
Classstring?nullAdditional CSS classes

DialogClose

ParameterTypeDefaultDescription
ChildContentRenderFragmentElement that closes the dialog on click

Accessibility

  • Focus is trapped inside the dialog while open.
  • Pressing Escape closes the dialog.
  • Proper role="dialog" and aria-labelledby / aria-describedby attributes are applied.
  • Focus returns to the trigger element when the dialog closes.

On this page