Alert Dialog
A modal dialog that asks for an answer before going on — to confirm, to cancel. In the look of the app's style. For a dialog that can simply be dismissed, use a Dialog.
Usage
import { Component, ViewEncapsulation } from '@angular/core';import { ScAlertDialog, ScAlertDialogAction, ScAlertDialogCancel, ScAlertDialogDescription, ScAlertDialogFooter, ScAlertDialogHeader, ScAlertDialogPortal, ScAlertDialogProvider, ScAlertDialogTitle, ScAlertDialogTrigger, ScButton,} from '@semantic-components/ui';
@Component({ selector: 'app-alert-dialog-usage-demo', imports: [ ScAlertDialog, ScAlertDialogAction, ScAlertDialogCancel, ScAlertDialogDescription, ScAlertDialogFooter, ScAlertDialogHeader, ScAlertDialogPortal, ScAlertDialogProvider, ScAlertDialogTitle, ScAlertDialogTrigger, ScButton, ], template: ` <div scAlertDialogProvider> <button scButton scAlertDialogTrigger variant="outline"> Show Dialog </button> <ng-template scAlertDialogPortal> <div scAlertDialog> <div scAlertDialogHeader> <h2 scAlertDialogTitle>Are you absolutely sure?</h2> <p scAlertDialogDescription> This action cannot be undone. This will permanently delete your account and remove your data from our servers. </p> </div> <div scAlertDialogFooter> <button scAlertDialogCancel>Cancel</button> <button scAlertDialogAction>Continue</button> </div> </div> </ng-template> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class AlertDialogUsageDemo {}Anatomy
Every part is a directive on your element. The dialog is in a template, rendered while it is open, over a backdrop; it is an alertdialog, named by its title and described by its description. Cancel and the action close it; do the work on the action's (click), or follow [(open)].
import { ScAlertDialogProvider, ScAlertDialogTrigger, ScAlertDialogPortal, ScAlertDialog, ScAlertDialogHeader, ScAlertDialogMedia, ScAlertDialogTitle, ScAlertDialogDescription, ScAlertDialogFooter, ScAlertDialogCancel, ScAlertDialogAction,} from '@semantic-components/ui';<div scAlertDialogProvider [(open)]="open"> <button scButton scAlertDialogTrigger>…</button> <ng-template scAlertDialogPortal> <div scAlertDialog> <div scAlertDialogHeader> <div scAlertDialogMedia><svg></svg></div> <h2 scAlertDialogTitle>…</h2> <p scAlertDialogDescription>…</p> </div> <div scAlertDialogFooter> <button scAlertDialogCancel>…</button> <button scAlertDialogAction>…</button> </div> </div> </ng-template></div>Keyboard
- Open, focus goes into the dialog — to its first button, Cancel: put the least harmful answer first.
- Tab and Shift + Tab stay in the dialog.
- Escape closes it, as Cancel does. A click outside doesn't: it wants an answer.
- Closed, focus goes back to the trigger.
Examples
Basic
import { Component, ViewEncapsulation } from '@angular/core';import { ScAlertDialog, ScAlertDialogAction, ScAlertDialogCancel, ScAlertDialogDescription, ScAlertDialogFooter, ScAlertDialogHeader, ScAlertDialogPortal, ScAlertDialogProvider,Small
import { Component, ViewEncapsulation } from '@angular/core';import { ScAlertDialog, ScAlertDialogAction, ScAlertDialogCancel, ScAlertDialogDescription, ScAlertDialogFooter, ScAlertDialogHeader, ScAlertDialogPortal, ScAlertDialogProvider,Media
import { Component, ViewEncapsulation } from '@angular/core';import { ScAlertDialog, ScAlertDialogAction, ScAlertDialogCancel, ScAlertDialogDescription, ScAlertDialogFooter, ScAlertDialogHeader, ScAlertDialogMedia, ScAlertDialogPortal,Small with Media
import { Component, ViewEncapsulation } from '@angular/core';import { ScAlertDialog, ScAlertDialogAction, ScAlertDialogCancel, ScAlertDialogDescription, ScAlertDialogFooter, ScAlertDialogHeader, ScAlertDialogMedia, ScAlertDialogPortal,Destructive
import { Component, ViewEncapsulation } from '@angular/core';import { ScAlertDialog, ScAlertDialogAction, ScAlertDialogCancel, ScAlertDialogDescription, ScAlertDialogFooter, ScAlertDialogHeader, ScAlertDialogMedia, ScAlertDialogPortal,RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScAlertDialog, ScAlertDialogAction, ScAlertDialogCancel, ScAlertDialogDescription, ScAlertDialogFooter, ScAlertDialogHeader, ScAlertDialogMedia,API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScAlertDialogProvider | div[scAlertDialogProvider], span[scAlertDialogProvider] | Holds the state: [(open)] (default false). Puts the dialog in an overlay, over a backdrop, while open. |
ScAlertDialogTrigger | button[scAlertDialogTrigger] | Opens it; behaviour only, on any button (scButton for the look). |
ScAlertDialogPortal | ng-template[scAlertDialogPortal] | The template of the dialog, rendered while open. |
ScAlertDialog | div[scAlertDialog] | The dialog: role alertdialog, modal, named by its title. Input size: 'default' or 'sm' (narrower, centered, two buttons side by side). |
ScAlertDialogHeader | div[scAlertDialogHeader] | The media, title and description. |
ScAlertDialogMedia | div[scAlertDialogMedia] | An icon, beside the title (above it in a small dialog). |
ScAlertDialogTitle, ScAlertDialogDescription | h2[scAlertDialogTitle], p[scAlertDialogDescription] | Name and describe the dialog. |
ScAlertDialogFooter | div[scAlertDialogFooter] | The buttons: stacked on a phone, in a row beyond. |
ScAlertDialogCancel, ScAlertDialogAction | button[scAlertDialogCancel], button[scAlertDialogAction] | Close it. Buttons in the style's look: inputs variant ('outline' and 'default') and size. |