Dialog Compound modal dialog overlay for displaying content that requires user attention.
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.
< 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 ; }
}
< 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 ; }
}
< 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 ; }
}
Parameter Type Default Description OpenboolfalseControls the dialog open state OpenChangedEventCallback<bool>— Callback when open state changes ChildContentRenderFragment— Dialog sub-components
Parameter Type Default Description ChildContentRenderFragment— Element that opens the dialog on click
Parameter Type Default Description ChildContentRenderFragment— Modal body content Classstring?nullAdditional CSS classes
Parameter Type Default Description ChildContentRenderFragment— Section content Classstring?nullAdditional CSS classes
Parameter Type Default Description ChildContentRenderFragment— Text content Classstring?nullAdditional CSS classes
Parameter Type Default Description ChildContentRenderFragment— Element that closes the dialog on click
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.