Skip to content
Overlay Modal

Modal

A native modal dialog: the page becomes inert and focus stays inside.

On this page

Examples

Edit profile

Changes are saved when you close the dialog.

Dialog: closed

Razor
<KlyModal @bind-Open="_open" Title="Edit profile" Description="Changes are saved when you close the dialog.">
    <ChildContent><KlyButton Label="Edit profile" Variant="ButtonVariant.Outline" data-testid="modal-trigger" /></ChildContent>
    <Body>
        <div class="flex flex-col gap-4">
            <KlyFormField Label="Name"><KlyInput Value="Ada Lovelace" /></KlyFormField>
            <KlyFormField Label="Bio"><KlyTextarea Rows="3" /></KlyFormField>
        </div>
    </Body>
    <Footer>
        <KlyButton Label="Cancel" Color="KlyColor.Neutral" Variant="ButtonVariant.Ghost" data-kly-close />
        <KlyButton Label="Save" data-kly-close data-testid="modal-save" />
    </Footer>
</KlyModal>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="modal-state">Dialog: @(_open ? "open" : "closed")</p>

@code {
    private bool _open;
}

Confirmation

Not dismissible: Escape and the backdrop do nothing.

Delete project?

This removes the project and its history. It cannot be undone.

Razor
<KlyModal Title="Delete project?" Description="This removes the project and its history. It cannot be undone." Dismissible="false" Close="false" Size="KlySize.Sm">
    <ChildContent><KlyButton Label="Delete project" Color="KlyColor.Error" Variant="ButtonVariant.Soft" /></ChildContent>
    <Footer>
        <KlyButton Label="Cancel" Color="KlyColor.Neutral" Variant="ButtonVariant.Outline" data-kly-close />
        <KlyButton Label="Delete" Color="KlyColor.Error" data-kly-close />
    </Footer>
</KlyModal>

Nested

A confirmation opened from a modal closes on its own.

Edit invoice

Discard changes?

Razor
<KlyModal Title="Edit invoice" data-testid="outer-modal">
    <ChildContent><KlyButton Label="Edit invoice" Variant="ButtonVariant.Outline" /></ChildContent>
    <Body>
        <KlyModal Title="Discard changes?" Size="KlySize.Sm" Close="false">
            <ChildContent><KlyButton Label="Discard" Color="KlyColor.Error" Variant="ButtonVariant.Soft" /></ChildContent>
            <Footer>
                <KlyButton Label="Keep editing" Color="KlyColor.Neutral" Variant="ButtonVariant.Outline" data-kly-close />
            </Footer>
        </KlyModal>
    </Body>
</KlyModal>

With a select

Back closes the open list first, then the modal.

Shipping

Choose where to ship the order.

France
Germany
Italy
Razor
<KlyModal Title="Shipping" Description="Choose where to ship the order.">
    <ChildContent><KlyButton Label="Ship order" Variant="ButtonVariant.Outline" data-testid="modal-select-trigger" /></ChildContent>
    <Body>
        <KlyFormField Label="Country">
            <KlySelect @bind-Value="_country" Items="Countries" Placeholder="Choose a country" data-testid="modal-country" />
        </KlyFormField>
    </Body>
    <Footer><KlyButton Label="Close" Color="KlyColor.Neutral" Variant="ButtonVariant.Ghost" data-kly-close /></Footer>
</KlyModal>

@code {
    private string? _country;

    private static readonly KlySelectItem[] Countries = [new("fr", "France"), new("de", "Germany"), new("it", "Italy")];
}

API

KlyModal

Modal dialog on the native dialog element, with a title, a description, a body and a footer. Opening and closing happen in the browser.

Parameters

Name Type Default Description
AriaLabel string Accessible name when there is no Title .
Class string Classes added to the root element, merged last so they win over the theme.
Close bool true Shows the close button in the header.
Description string Text under the title of the modal.
Dismissible bool true Escape and a click on the backdrop close the modal.
Open (@bind-Open) bool false Open state. Use @bind-Open : the browser closes the modal on its own (Escape, close button).
Size KlySize KlySize.Md Size of the modal, from Xs to Xl ; it changes the width of the dialog. Values: Xs, Sm, Md, Lg, Xl.
Title string Title of the modal, which also names the dialog.
Ui ModalUi Per-instance class overrides of the slots of the modal, see ModalUi . They are merged after the theme and the Class parameter wins on the root slot.

Slots

Name Type Description
Body RenderFragment Content of the body of the modal.
Footer RenderFragment Footer actions. Add data-kly-close to a button to make it close the modal.
ChildContent RenderFragment The trigger: its first button opens the modal.

Ui slots

Ui takes a ModalUi with one class string per slot, merged after the theme.

Slot Styles
Content Classes merged into the content slot of KlyModal , after the theme and the app configuration.
Header Classes merged into the header slot of KlyModal , after the theme and the app configuration.
Wrapper Classes merged into the wrapper slot of KlyModal , after the theme and the app configuration.
Title Classes merged into the title slot of KlyModal , after the theme and the app configuration.
Description Classes merged into the description slot of KlyModal , after the theme and the app configuration.
Close Classes merged into the close slot of KlyModal , after the theme and the app configuration.
Body Classes merged into the body slot of KlyModal , after the theme and the app configuration.
Footer Classes merged into the footer slot of KlyModal , after the theme and the app configuration.