sw-ui-alert

View as MarkdownOpen in Claude

Modal confirmation / alert dialog primitive built on the native <dialog> element. Resolves a Promise with the user’s choice when used via the companion showPrompt() helper.

1<sw-ui-alert id="confirm" title="Hang up?" confirm-label="Hang up" cancel-label="Stay"></sw-ui-alert>

Two interaction modes are selectable through the reflected type attribute:

  • confirm (default) — renders both Cancel and OK buttons; the returned Promise resolves to true on accept and false on reject / dialog close.
  • alert — renders only OK; the Promise resolves to true once acknowledged or the dialog is dismissed.

The dialog uses the platform <dialog> element so focus management, ESC-to-dismiss, and ::backdrop styling all come for free.

Class: SwUiAlert · Module: packages/web-components/src/components/UI/sw-ui-alert.ts

class: SwUiAlert, sw-ui-alert

Fields

title
string

title field.

description
stringDefaults to ''

description field.

type
PromptTypeDefaults to 'confirm'

type field.

Methods

NamePrivacyDescriptionParametersReturnInherited From
showOpens the prompt and returns a promise that resolves with the user’s choice.Promise<boolean>

Attributes

NameFieldInherited From
titletitle
descriptiondescription
typetype

CSS Properties

NameDefaultDescription
--type-family-bodyDialog font family.
--radius-mdDialog border radius.
--shadow-mdDialog drop shadow.
--interactive-button-primary-bgBackground color of the accept button.
--interactive-button-primary-hoverHover background of the accept button.

Slots

NameDescription
Default slot for rich body content. When non-empty, takes priority over the `description` property.

Functions

NameDescriptionParametersReturn
showPromptProgrammatically show a prompt and await the user’s response.options: { title: string; description?: string; type?: PromptType; }Promise<boolean>

Events

NameDetailDescription
sw-ui-alert-acceptUser clicked OK / accepted. No detail.
sw-ui-alert-rejectUser clicked Cancel, closed via ESC, or