# 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 hook invoked before the standard header close (X) flow. `OpenChanged(false)` still fires. | | 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 Use `OnCloseButtonClick` for cleanup or confirmation-side effects that should run before the header X closes the dialog. The dialog still performs the standard close flow and fires `OpenChanged(false)` afterward: ```razor ... @code { private bool isOpen; private Task OnHeaderClose() { // Optional cleanup before the dialog closes. return Task.CompletedTask; } } ``` ### 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 ```