Popover

Rich content in a panel beside its trigger: a dialog, modal or not, opened by a click or a hover. In the look of the app's style.

OverlayExperimental

Usage

import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScField,  ScFieldGroup,  ScInput,  ScLabel,  ScPopover,  ScPopoverDescription,  ScPopoverHeader,  ScPopoverPortal,  ScPopoverProvider,  ScPopoverTitle,  ScPopoverTrigger,  ScSelectOnFocus,} from '@semantic-components/ui';
@Component({  selector: 'app-popover-usage-demo',  imports: [    ScButton,    ScField,    ScFieldGroup,    ScInput,    ScLabel,    ScPopover,    ScPopoverDescription,    ScPopoverHeader,    ScPopoverPortal,    ScPopoverProvider,    ScPopoverTitle,    ScPopoverTrigger,    ScSelectOnFocus,  ],  template: `    <div scPopoverProvider alignment="start">      <button scButton scPopoverTrigger variant="outline">Open Popover</button>      <ng-template scPopoverPortal>        <div scPopover class="w-64">          <div scPopoverHeader>            <h2 scPopoverTitle>Dimensions</h2>            <p scPopoverDescription>Set the dimensions for the layer.</p>          </div>          <div scFieldGroup class="gap-4">            <div scField orientation="horizontal">              <label scLabel class="w-1/2">Width</label>              <input                scInput                value="100%"                cdkFocusInitial                scSelectOnFocus="program"              />            </div>            <div scField orientation="horizontal">              <label scLabel class="w-1/2">Height</label>              <input scInput value="25px" />            </div>          </div>        </div>      </ng-template>    </div>  `,  host: { class: 'flex w-full justify-center' },  encapsulation: ViewEncapsulation.None,})export class PopoverUsageDemo {}

Anatomy

Every part is a directive on your element; the trigger, the title, the content and the close button are yours.

import {  ScPopoverProvider, ScPopoverTrigger, ScPopoverPortal,  ScPopover, ScPopoverHeader, ScPopoverTitle,  ScPopoverDescription, ScPopoverClose,} from '@semantic-components/ui';
<div scPopoverProvider side="…" alignment="…">  <button scButton scPopoverTrigger>…</button>  <ng-template scPopoverPortal>    <div scPopover>      <div scPopoverHeader>        <h2 scPopoverTitle>…</h2>        <p scPopoverDescription>…</p>      </div>      …      <button scPopoverClose>…</button>    </div>  </ng-template></div>

Accessibility

  • A dialog (role="dialog"), named by its title and described by its description; its trigger says it opens one (aria-haspopup, aria-expanded).
  • Opening moves focus into it (its first field, or the one marked cdkFocusInitial); closing gives it back to the trigger. Escape or a press outside closes it.
  • Not modal (default): Tab out of it closes it and goes on from the trigger. trap-focus keeps Tab inside; modal also stops the page behind.
  • Open on hover is for extra help (an infotip): a click opens it too, so touch and keyboard users reach it.

Examples

Basic

import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScPopover,  ScPopoverDescription,  ScPopoverHeader,  ScPopoverPortal,  ScPopoverProvider,  ScPopoverTitle,  ScPopoverTrigger,

Alignments

import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,  ScPopoverTrigger,} from '@semantic-components/ui';
/** alignment: start, center (default), end — logical: start is the reading start. */

Sides

import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,  ScPopoverTrigger,} from '@semantic-components/ui';
/** side: bottom (default), top, left, right — or inline-start, inline-end, which follow the direction. It flips when there is no room. */

Open on hover

Storage used: 12.4 GB
import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScPopover,  ScPopoverDescription,  ScPopoverHeader,  ScPopoverPortal,  ScPopoverProvider,  ScPopoverTitle,  ScPopoverTrigger,

Modal

import { Component, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScField,  ScFieldGroup,  ScInput,  ScKbd,  ScLabel,  ScPopover,  ScPopoverDescription,

Controlled

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScButton,  ScPopover,  ScPopoverClose,  ScPopoverDescription,  ScPopoverHeader,  ScPopoverPortal,  ScPopoverProvider,  ScPopoverTitle,

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScButton,  ScPopover,  ScPopoverDescription,  ScPopoverHeader,  ScPopoverPortal,  ScPopoverProvider,  ScPopoverTitle,

API reference

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

PartSelectorDescription
ScPopoverProviderdiv[scPopoverProvider], span[scPopoverProvider] [(open)], modal (false, 'trap-focus', true), side ('bottom', 'top', 'left', 'right', 'inline-start', 'inline-end'), align ('start', 'center', 'end'), offset (4), origin (another anchor).
ScPopoverTriggerbutton[scPopoverTrigger] Your button: toggles it (aria-haspopup, aria-expanded); openOnHover, delay (300), closeDelay (0).
ScPopoverPortal, ScPopoverng-template[…], div[scPopover] The content, rendered while open; the popover (role="dialog"), named and described, animated.
ScPopoverHeader, ScPopoverTitle, ScPopoverDescriptiondiv[…], [scPopoverTitle], p[…] Its title (it names it; the level is yours) and description.
ScPopoverClosebutton[scPopoverClose] Closes it: the style's button, variant and size (ghost, icon-xs). Name it.