Dialog
A window over the page, which waits until it is closed: the page behind it can't be reached. In the look of the app's style.
Usage
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScDialog, ScDialogClose, ScDialogDescription, ScDialogFooter, ScDialogHeader, ScDialogPortal, ScDialogProvider, ScDialogTitle, ScDialogTrigger, ScField, ScFieldGroup, ScInput, ScLabel, ScSelectOnFocus,} from '@semantic-components/ui';import { SiXIcon } from '@semantic-icons/lucide-icons';
@Component({ selector: 'app-dialog-usage-demo', imports: [ ScButton, ScDialogProvider, ScDialogTrigger, ScDialogPortal, ScDialog, ScDialogClose, ScDialogHeader, ScDialogTitle, ScDialogDescription, ScDialogFooter, ScFieldGroup, ScField, ScLabel, ScInput, ScSelectOnFocus, SiXIcon, ], template: ` <div scDialogProvider [(open)]="open"> <button scButton variant="outline" scDialogTrigger>Open Dialog</button> <ng-template scDialogPortal> <div scDialog class="sm:max-w-sm"> <button scDialogClose> <svg siXIcon></svg> <span class="sr-only">Close</span> </button> <div scDialogHeader> <h2 scDialogTitle>Edit profile</h2> <p scDialogDescription> Make changes to your profile here. Click save when you're done. </p> </div> <div scFieldGroup> <div scField> <label scLabel>Name</label> <input cdkFocusInitial scSelectOnFocus="program" scInput value="Pedro Duarte" /> </div> <div scField> <label scLabel>Username</label> <input scInput value="@peduarte" /> </div> </div> <div scDialogFooter> <button scDialogClose variant="outline" size="default"> Cancel </button> <button scButton (click)="save()">Save changes</button> </div> </div> </ng-template> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class DialogUsageDemo { private readonly open = signal(false);
/** Save: your code runs first; the dialog closes when it's done. */ private save(): void { // Send the changes, check them… this.open.set(false); }}Anatomy
Every part is a directive on your element; the text, the buttons and their names are yours. The dialog is in a template, rendered while it is open.
import { ScDialogProvider, ScDialogTrigger, ScDialogPortal, ScDialog, ScDialogClose, ScDialogHeader, ScDialogTitle, ScDialogDescription, ScDialogBody, ScDialogFooter,} from '@semantic-components/ui';<div scDialogProvider [(open)]="open"> <button scButton scDialogTrigger>…</button> <ng-template scDialogPortal> <div scDialog> <button scDialogClose>…</button> <div scDialogHeader> <h2 scDialogTitle>…</h2> <p scDialogDescription>…</p> </div> <div scDialogBody>…</div> <div scDialogFooter> <button scDialogClose variant="outline" size="default">Cancel</button> <button scButton (click)="save()">…</button> </div> </div> </ng-template></div>Closing
- scDialogClose closes it, on any button — the ✕ straight in the dialog (in its corner), Cancel or Done in the footer. It is the style's button: ghost and icon-sized for the ✕, variant="outline" size="default" for Cancel — no scButton.
- When your code runs first — Save checks and sends the form — the button is yours, and closes the dialog through [(open)] when it is done (or keeps it open, to show what is wrong).
- Escape and a click outside close it too. Focus stays in it while it is open, and goes back to what opened it.
Examples
Custom Close Button
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScDialog, ScDialogClose, ScDialogDescription, ScDialogFooter, ScDialogHeader, ScDialogPortal, ScDialogProvider,No Close Button
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScDialog, ScDialogDescription, ScDialogHeader, ScDialogPortal, ScDialogProvider, ScDialogTitle, ScDialogTrigger,Sticky Footer
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScDialog, ScDialogBody, ScDialogClose, ScDialogDescription, ScDialogFooter, ScDialogHeader, ScDialogPortal,Scrollable Content
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScDialog, ScDialogBody, ScDialogClose, ScDialogDescription, ScDialogHeader, ScDialogPortal, ScDialogProvider,RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScDialog, ScDialogClose, ScDialogDescription, ScDialogFooter, ScDialogHeader, ScDialogPortal,API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScDialogProvider | div[scDialogProvider], span[scDialogProvider] | [(open)]. Renders the dialog over the page, centred, over the backdrop; Escape and a click outside close it. |
ScDialogTrigger | button[scDialogTrigger] | Opens it; behaviour only, on any button. |
ScDialogPortal, ScDialog | ng-template[scDialogPortal], div[scDialog] | The dialog (role dialog, modal), rendered while open; named by its title, described by its description. It takes the direction and language of where it is opened. |
ScDialogClose | button[scDialogClose] | Closes it: the style’s button, variant and size (ghost, icon-sm: the ✕). Straight in the dialog: in its corner. |
ScDialogHeader, ScDialogFooter | div[scDialogHeader], div[scDialogFooter] | The title and description; the buttons. |
ScDialogBody | div[scDialogBody] | The content between them: past half the screen it scrolls, edge to edge, while the header and the footer stay. |
ScDialogTitle, ScDialogDescription | h2[scDialogTitle], p[scDialogDescription] | Its name and its description. |