# SbDialog A modal dialog component built on the native HTML `` element with header, body, and footer slots. ## Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | Open | bool | false | Whether the dialog is open | | Title | string? | null | Dialog title displayed in header | | Size | SbDialogSize | Md | Dialog size preset | | Width | string? | null | Override width; value applied as-is to CSS (e.g. "800px", "80%") | | MaxWidth | string? | null | Override max-width; value applied as-is to CSS (e.g. "800px", "80%") | | Height | string? | null | Override height; value applied as-is to CSS (e.g. "80vh", "600px", "80%") | | MaxHeight | string? | null | Override max-height; value applied as-is to CSS (e.g. "90vh", "800px", "80%") | | CloseOnEscape | bool | true | Whether to close on Escape key | | CloseOnBackdropClick | bool | true | Whether to close when clicking backdrop | | ShowCloseButton | bool | true | Whether to show the close button | | OnCloseButtonClick | EventCallback | - | Optional. When set, the header close (X) button invokes this instead of the default close (e.g. pass your modal's Hide so @bind-Open stays in sync) | | Class | string? | null | Additional CSS classes | | Style | string? | null | Inline styles | | AdditionalAttributes | Dictionary\? | null | Additional HTML attributes | ## Events | Event | Type | Description | |-------|------|-------------| | OpenChanged | EventCallback\ | Fired when open state changes | | OnClose | EventCallback\ | Fired when dialog closes with reason | ## Templates / Slots | Slot | Type | Description | |------|------|-------------| | Header | RenderFragment | Custom header content (replaces Title) | | ChildContent | RenderFragment | Dialog body content | | Footer | RenderFragment | Footer content for action buttons | ## SbDialogSize Enum ```csharp public enum SbDialogSize { Sm, // 400px max-width Md, // 600px max-width Lg, // 800px max-width Xl, // 1024px max-width FullScreen // Full screen } ``` ## SbDialogCloseReason Enum ```csharp public enum SbDialogCloseReason { Escape, // User pressed Escape key Backdrop, // User clicked the backdrop CloseButton, // User clicked the close button Programmatic // Closed via code } ``` ## CSS Classes - `sb-dialog` - Base class - `sb-dialog--sm|md|lg|xl|fullscreen` - Size variants - `sb-dialog__container` - Inner container - `sb-dialog__header` - Header section - `sb-dialog__title` - Title text - `sb-dialog__close-btn` - Close button - `sb-dialog__body` - Body content - `sb-dialog__footer` - Footer section ## Accessibility - Uses native `` element - `aria-labelledby` links to title - `aria-modal="true"` indicates modal - Close button has `aria-label="Close"` ## Examples ### Basic Usage ```razor Open Dialog

This is the dialog content.

@code { private bool isOpen = false; } ``` ### With Footer Actions ```razor

You have unsaved changes. Would you like to save them?

Discard Save Changes
``` ### Different Sizes ```razor Small content Large content Full screen content ``` ### Custom Dimensions (Width, MaxWidth, Height, MaxHeight) Override the Size preset with inline dimensions. Inline styles override the size class (e.g. `sb-dialog--lg`): ```razor Content with custom width Content with custom height ``` ### Custom Header ```razor

Warning

This action cannot be undone.

``` ### Prevent Accidental Close ```razor
Submit
``` ### Custom Close Button Handler (e.g. for @bind-Open in a wrapper modal) When the dialog is used inside a modal that binds Open from a parent, the header X should call the same close logic as Cancel so the binding stays in sync: ```razor ... @code { [Parameter] public bool Open { get; set; } [Parameter] public EventCallback OpenChanged { get; set; } private void Hide() => OpenChanged.InvokeAsync(false); } ``` ### Handle Close Reason ```razor

Content

@code { private void HandleClose(SbDialogCloseReason reason) { Console.WriteLine($"Dialog closed: {reason}"); if (reason == SbDialogCloseReason.Backdrop) { // Show warning about unsaved changes } } } ``` ### Form Dialog ```razor User Admin ```