Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

ConfirmDialog

Since 0.1.0-alpha.24
Asks before a menu item, row action or link acts: one dialog for a whole list.

One dialog that asks before any of several things act: a menu item, a row's action, an icon button, a link. It names what it's for (For), and they stay as they are: a click on one opens the dialog, and confirming does what the click would have done, whether that posts a form, follows a link or runs C#.

Asking before each row's action

One ConfirmDialog asks for every row's action: set For to an id, or to a selector such as .revoke-key. To name the row in the question, write {0} in Title and put data-confirm on each button. For a single button that asks first, use a ConfirmButton.

Static

Preview

API keys

  • Production server

    Last used 2 hours ago

  • CI pipeline

    Last used yesterday

  • Dana's laptop

    Last used Oct 3

Revoke {0}?

Apps that use this key stop working at once.

Code

Usage.razor
<form method="post" @onsubmit="() => Revoke(Posted ?? _revoked)" @formname="api-keys" data-enhance>
    <AntiforgeryToken />
    <Card Title="API keys" Size="ControlSize.Sm">
        <List Plain>
            @foreach (var key in Keys)
            {
                <ListItem Icon="Lucide.KeyRound" Description="@key.Used">
                    @key.Name
                    <ListItemActions>
                        @if (_revoked == key.Id)
                        {
                            <Badge Status="Status.Neutral">Revoked</Badge>
                        }
                        else
                        {
                            <IconButton Class="revoke-key" data-confirm="@key.Name" Label="@($"Revoke {key.Name}")" Icon="Lucide.Trash"
                                        Submit Name="revoke" Value="@key.Id" OnClick="() => Revoke(key.Id)"
                                        Variant="ButtonVariant.Ghost" Accent="Accent.Neutral" Size="ControlSize.Sm" />
                        }
                    </ListItemActions>
                </ListItem>
            }
        </List>
    </Card>
</form>

@* One dialog for every row's button: {0} is the clicked button's data-confirm. *@
<ConfirmDialog For=".revoke-key" Title="Revoke {0}?" Message="Apps that use this key stop working at once."
               ConfirmText="Revoke key" Accent="Accent.Danger" />

@code {
    // Static pages: the confirmed button's Name=Value posts with the form.
    [SupplyParameterFromForm(FormName = "api-keys", Name = "revoke")]
    private string? Posted { get; set; }

    private string? _revoked;

    // Interactive pages post nothing (Posted stays empty), so OnClick says which key it was.
    private void Revoke(string? id) => _revoked = id;

}

Static: Confirming posts the form with the pressed button's revoke value.

Add this example to a page with the izzy CLI:

bash
izzy add component ConfirmDialog --at <file>:<line>

Details

For is an id, or a CSS selector when it starts with "#", "." or "[", so one dialog serves every row of a list. {0} in Title and Message is the data-confirm value of the one clicked, such as the row's name.

Put it outside any form. For a button of its own that asks first, with JavaScript off too, use ConfirmButton.

Mode support

What works in each mode, ConfirmDialog
FeatureStaticInteractive
A click on what it's for opens the dialog instead of actingYesYes
Confirming posts the form, follows the link or runs the C# of the one clickedYesYes
{0} in Title and Message names the one clickedYesYes

Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.

Without JavaScript

Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off. With JavaScript off, the buttons and links it's for act without asking.

Accessibility

  • A modal dialog with role="alertdialog", named by Title and described by Message and Body.
  • Cancel ("Cancel", CancelText) takes focus when it opens, so Enter doesn't confirm by accident.
  • While it's open, focus stays in the dialog; Escape closes it and focus returns to what was clicked, or to its menu's button when that was a menu item. A backdrop click doesn't close it, and there's no close button.
  • With JavaScript off, what it's for acts without asking.

Parameters

ConfirmDialog parameters
PropTypeDefault
ForWhat it asks for: the id of a button or link, or a CSS selector when it starts with #, . or [, such as .delete-note for every row's Delete.stringRequired
TitleThe question, such as "Delete this note?".stringRequired
MessageA line under the question, such as "This can't be undone." {0} works as in Title.string?
BodyMore content under the question, the same for whichever was clicked.RenderFragment?
ConfirmTextThe confirm button's text, such as "Delete".string?"Confirm"
CancelTextThe cancel button's text.string?"Cancel"
AccentThe confirm button's color: Danger for deleting.AccentAccent.Primary
IdThe dialog's id.string?

See also

  • ConfirmButton: asks the user to confirm in an alert dialog before acting.
  • Dialog: opens a native modal dialog from a trigger, a link or C#.
  • Menu: opens a popover menu of links, form posts and actions.

Connection lost

Rejoining the server…