ConfirmDialog


Use ConfirmDialog component when you want the user to verify or accept something.

API Documentation

How it works #

The ConfirmDialog component displays a modal dialog prompting the user to confirm or cancel an action, such as deleting an item. It is ideal for scenarios where user verification is required before proceeding.

How to use:
  1. Add the ConfirmDialog component to your page and assign it a reference using @ref.
  2. Trigger the dialog by calling ShowAsync on the referenced component, passing a title and message as needed.
  3. Await the result of ShowAsync to determine if the user confirmed (true) or canceled (false), and handle the outcome accordingly.
This demo shows the basic usage of ConfirmDialog for confirming a delete operation.
RAZOR
<ConfirmDialog @ref="confirmDialogRef" />

<Button Color="ButtonColor.Danger" @onclick="ShowConfirmationDialogAsync"> Delete Employee </Button>

@code {
    private ConfirmDialog confirmDialogRef = default!;

    private async Task ShowConfirmationDialogAsync()
    {
        var result = await confirmDialogRef.ShowAsync(
            title: "Are you sure you want to delete this item?",
            message: "This action cannot be undone."
        );

        if (result)
        {
            Console.WriteLine("Item deleted.");
            // Delete the item
        }
        else
        {
            Console.WriteLine("Item not deleted.");
            // Do nothing
        }
    }
}

Change buttons text and color #

You can customize the ConfirmDialog buttons to match your application's language and style. The button text and color can be changed using the ConfirmDialogOptions parameter.

How to customize:
  1. Create a ConfirmDialogOptions object and set properties like YesButtonText, NoButtonText, YesButtonColor, and NoButtonColor.
  2. Pass the options object to ShowAsync when displaying the dialog.
  3. The dialog will reflect your custom button labels and colors, providing a tailored user experience.
This demo demonstrates how to change the button text and color for the confirmation dialog.
RAZOR
<ConfirmDialog @ref="confirmDialogRef" />

<Button Color="ButtonColor.Danger" @onclick="ShowConfirmationDialogAsync"> Delete Employee </Button>

@code {
    private ConfirmDialog confirmDialogRef = default!;

    private async Task ShowConfirmationDialogAsync()
    {
        var options = new ConfirmDialogOptions
            {
                YesButtonText = "Yes, delete it",
                NoButtonText = "No, keep it",
                YesButtonColor = ButtonColor.Danger,
                NoButtonColor = ButtonColor.Info
            };

        var result = await confirmDialogRef.ShowAsync(
            title: "Are you sure you want to delete this item?",
            message: "You won't be able to revert this!",
            options: options
        );

        if (result)
        {
            Console.WriteLine("Item deleted.");
            // Delete the item
        }
        else
        {
            Console.WriteLine("Item not deleted.");
            // Do nothing
        }
    }
}
DO YOU KNOW?
This demo website is built using the BlazorExpress.Bulma library and published on the Azure Web App. See our source code on GitHub.