Native Dialog

The Dialog — its parts, its look, its behaviour — on the browser's own <dialog> element.

FeedbackExperimental

Usage

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScButton,  ScField,  ScFieldGroup,  ScInput,  ScLabel,  ScNativeDialog,  ScNativeDialogClose,  ScNativeDialogDescription,  ScNativeDialogFooter,  ScNativeDialogHeader,  ScNativeDialogPortal,  ScNativeDialogProvider,  ScNativeDialogTitle,  ScNativeDialogTrigger,  ScSelectOnFocus,} from '@semantic-components/ui';import { SiXIcon } from '@semantic-icons/lucide-icons';
@Component({  selector: 'app-native-dialog-usage-demo',  imports: [    ScButton,    ScNativeDialogProvider,    ScNativeDialogTrigger,    ScNativeDialogPortal,    ScNativeDialog,    ScNativeDialogClose,    ScNativeDialogHeader,    ScNativeDialogTitle,    ScNativeDialogDescription,    ScNativeDialogFooter,    ScFieldGroup,    ScField,    ScLabel,    ScInput,    ScSelectOnFocus,    SiXIcon,  ],  template: `    <div scNativeDialogProvider [(open)]="open">      <button scButton variant="outline" scNativeDialogTrigger>        Open Dialog      </button>      <ng-template scNativeDialogPortal>        <dialog scNativeDialog class="sm:max-w-sm">          <button scNativeDialogClose>            <svg siXIcon></svg>            <span class="sr-only">Close</span>          </button>          <div scNativeDialogHeader>            <h2 scNativeDialogTitle>Edit profile</h2>            <p scNativeDialogDescription>              Make changes to your profile here. Click save when you're done.            </p>          </div>          <div scFieldGroup>            <div scField>              <label scLabel>Name</label>              <input                autofocus                scSelectOnFocus="program"                scInput                value="Pedro Duarte"              />            </div>            <div scField>              <label scLabel>Username</label>              <input scInput value="@peduarte" />            </div>          </div>          <div scNativeDialogFooter>            <button scNativeDialogClose variant="outline" size="default">              Cancel            </button>            <button scButton (click)="save()">Save changes</button>          </div>        </dialog>      </ng-template>    </div>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class NativeDialogUsageDemo {  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

The Dialog's, part for part: 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 {  ScNativeDialogProvider, ScNativeDialogTrigger, ScNativeDialogPortal,  ScNativeDialog, ScNativeDialogClose, ScNativeDialogHeader,  ScNativeDialogTitle, ScNativeDialogDescription, ScNativeDialogBody,  ScNativeDialogFooter,} from '@semantic-components/ui';
<div scNativeDialogProvider [(open)]="open">  <button scButton scNativeDialogTrigger>…</button>  <ng-template scNativeDialogPortal>    <dialog scNativeDialog>      <button scNativeDialogClose>…</button>      <div scNativeDialogHeader>        <h2 scNativeDialogTitle>…</h2>        <p scNativeDialogDescription>…</p>      </div>      <div scNativeDialogBody>…</div>      <div scNativeDialogFooter>        <button scNativeDialogClose variant="outline" size="default">Cancel</button>        <button scButton (click)="save()">…</button>      </div>    </dialog>  </ng-template></div>

Native

What the Dialog builds with the CDK, the browser does here: the dialog is shown with showModal(), in the top layer, above everything, whatever the page's stacking.

  • The page behind is inert, and focus stays in the dialog — no focus trap of ours.
  • It takes the direction and language of where it is written, as any element: it isn't moved to the end of the page.
  • Its first focus is the browser's: the first focusable element, or the one with autofocus (the Dialog's cdkFocusInitial).

Closing

  • scNativeDialogClose 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; it fades out, then the browser gives focus back to what opened it.

Examples

Custom Close Button

import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScField,  ScInput,  ScLabel,  ScNativeDialog,  ScNativeDialogClose,  ScNativeDialogDescription,  ScNativeDialogFooter,

No Close Button

import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScNativeDialog,  ScNativeDialogDescription,  ScNativeDialogHeader,  ScNativeDialogPortal,  ScNativeDialogProvider,  ScNativeDialogTitle,  ScNativeDialogTrigger,

Sticky Footer

import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScNativeDialog,  ScNativeDialogBody,  ScNativeDialogClose,  ScNativeDialogDescription,  ScNativeDialogFooter,  ScNativeDialogHeader,  ScNativeDialogPortal,

Scrollable Content

import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScNativeDialog,  ScNativeDialogBody,  ScNativeDialogClose,  ScNativeDialogDescription,  ScNativeDialogHeader,  ScNativeDialogPortal,  ScNativeDialogProvider,

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import {  ScButton,  ScField,  ScFieldGroup,  ScInput,  ScLabel,  ScNativeDialog,  ScNativeDialogClose,

API reference

Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScNativeDialogProviderdiv[scNativeDialogProvider], span[scNativeDialogProvider] [(open)]. Renders the dialog in place while open, the page behind kept from scrolling.
ScNativeDialogTriggerbutton[scNativeDialogTrigger] Opens it; behaviour only, on any button.
ScNativeDialogPortal, ScNativeDialogng-template[scNativeDialogPortal], dialog[scNativeDialog] The dialog, rendered while open and shown as a modal (showModal): the whole screen, the style’s backdrop and, centred, the panel in the Dialog’s look — your class goes on the panel. Named by its title, described by its description; Escape and a click outside close it.
ScNativeDialogClosebutton[scNativeDialogClose] Closes it: the style’s button, variant and size (ghost, icon-sm: the ✕). Straight in the dialog: in its corner.
ScNativeDialogHeader, ScNativeDialogFooterdiv[scNativeDialogHeader], div[scNativeDialogFooter] The title and description; the buttons.
ScNativeDialogBodydiv[scNativeDialogBody] The content between them: past half the screen it scrolls, edge to edge, while the header and the footer stay.
ScNativeDialogTitle, ScNativeDialogDescriptionh2[scNativeDialogTitle], p[scNativeDialogDescription] Its name and its description.