Skip to content
Glint UI

AlertDialog

A modal confirmation dialog that interrupts the user with important content and expects an explicit response.

Usage

import { AlertDialog } from "@glint/components/alert-dialog.slint";
export component AppWindow inherits Window {
in-out property <bool> deleting: false;
callback perform-delete();
VerticalLayout {
// your screen layout
}
// Last child of the window, sized to it: Slint has no portals, so what
// draws on top is what comes last.
AlertDialog {
width: parent.width;
height: parent.height;
open <=> root.deleting;
title: "Are you sure?";
description: "This action cannot be undone.";
action-label: "Delete";
confirmed => { root.perform-delete(); }
}
}

An AlertDialog is a focused confirmation modal that requires an explicit choice. Unlike Dialog, it provides no freeform body slot — its description is the entire message — and clicking the backdrop is intentionally a no-op so a stray click cannot dismiss an unanswered question.

Mount it last among the window’s children, sized to width: parent.width; height: parent.height.

Examples

Compact size

size offers two width presets: default (420px) for standard confirmation prompts and sm (320px) for brief questions that need little horizontal room.

Action variant

action-variant styles the confirm button with any ButtonVariant. It defaults to ButtonVariant.destructive for destructive confirmations, and you set ButtonVariant.default or ButtonVariant.outline when asking for confirmation of a non-destructive action.

Handling confirmation and cancellation

confirmed fires when the action button is pressed; cancelled fires when the Cancel button is pressed or when the user presses Escape. The alert dialog closes itself on either path.

Restoring focus

restore-focus fires on every close, so you can return keyboard focus to the button that triggered the alert dialog.

API Reference

Properties

PropertyTypeDefaultDescription
openin-out boolfalseTwo-way; consumer sets true to show, Glint sets false on close.
titlein stringno defaultHeading at the top of the modal.
descriptionin stringno defaultBody text describing the consequences of the action.
action-labelin string@tr("Continue")Label for the destructive button (right side).
cancel-labelin string@tr("Cancel")Label for the safe button (left side).
action-variantin ButtonVariantButtonVariant.destructiveStyle for the action button — defaults to destructive.
sizein AlertDialogSizeAlertDialogSize.defaultWidth preset — default or the compact sm.

Callbacks

CallbackDescription
confirmed()Fired when the action button is pressed; the modal closes itself.
cancelled()Fired on Cancel or Escape; the modal closes itself.
restore-focus()Fired on EVERY close, including one the consumer drives by setting open = false, so keyboard focus always gets a new home: restore-focus => { my-button.focus(); }. Slint exposes no "previously focused element", so only the trigger's owner can name it. Same contract Dialog, Sheet and Drawer publish.

Enums

EnumValues
ButtonVariantdefault, outline, secondary, ghost, link, destructive, glow, glass
AlertDialogSizedefault, sm

Accessibility

  • Role and name. Slint has no alertdialog role, so the open panel claims the closest landmark it has — a region — named by title and described by description. Assistive technology announces both upon presentation.
  • Initial focus. Opening the alert dialog moves keyboard focus to the Cancel button by default, ensuring that an accidental Enter keypress never triggers a destructive action.
  • Keyboard navigation. Tab and Shift+Tab cycle focus exclusively between the Cancel and Action buttons inside the modal card.
  • Keyboard dismissal. Escape fires cancelled() and closes the alert dialog.
  • No backdrop dismissal. Clicks on the dimmed scrim are ignored: unlike Dialog, an alert dialog requires the user to explicitly select one of the two choices.
  • Focus restoration. restore-focus fires on every close so focus can be returned to the opening trigger.
  • The trigger. The control that opens an alert dialog should set haspopup: true.