General
Popover
Usage#
import { WdsPopoverComponent } from '@wds/angular/popover';trigger slot and the content in the default slot. Name the panel with heading (or label when it has no title). For a short text on hover use Tooltip, for a list of actions Dropdown.
Examples#
Default#
heading and description add a title and a description at the top. A click outside, Escape or moving focus out of the panel closes it.
import { Component } from '@angular/core';
import { WdsPopoverComponent } from '@wds/angular/popover';
import { WdsButtonComponent } from '@wds/angular/button';
import { WdsFieldComponent, WdsFieldGroupComponent, WdsFieldLabelComponent } from '@wds/angular/field';
import { WdsInputComponent } from '@wds/angular/input';
@Component({
selector: 'app-popover-default-demo',
imports: [WdsPopoverComponent, WdsButtonComponent, WdsFieldGroupComponent, WdsFieldComponent, WdsFieldLabelComponent, WdsInputComponent],
template: `
<wds-popover heading="Dimensions" description="Set the dimensions for the layer.">
<wds-button slot="trigger" variant="outline">Open popover</wds-button>
<wds-field-group class="gap-3">
<wds-field orientation="horizontal">
<wds-field-label class="w-1/2">Width</wds-field-label>
<wds-input value="100%"></wds-input>
</wds-field>
<wds-field orientation="horizontal">
<wds-field-label class="w-1/2">Max. width</wds-field-label>
<wds-input value="300px"></wds-input>
</wds-field>
<wds-field orientation="horizontal">
<wds-field-label class="w-1/2">Height</wds-field-label>
<wds-input value="25px"></wds-input>
</wds-field>
<wds-field orientation="horizontal">
<wds-field-label class="w-1/2">Max. height</wds-field-label>
<wds-input value="none"></wds-input>
</wds-field>
</wds-field-group>
</wds-popover>
`,
})
export class PopoverDefaultDemo {}Side#
side places the panel bottom (default), top, left or right of the trigger. Without enough space it flips to the other side.
import { Component } from '@angular/core';
import { WdsPopoverComponent } from '@wds/angular/popover';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-popover-side-demo',
imports: [WdsPopoverComponent, WdsButtonComponent],
template: `
<div class="flex flex-wrap gap-2">
<wds-popover side="left" label="Left">
<wds-button slot="trigger" variant="outline">Left</wds-button>
<div>The panel opens on the left.</div>
</wds-popover>
<wds-popover side="top" label="Top">
<wds-button slot="trigger" variant="outline">Top</wds-button>
<div>The panel opens on the top.</div>
</wds-popover>
<wds-popover side="bottom" label="Bottom">
<wds-button slot="trigger" variant="outline">Bottom</wds-button>
<div>The panel opens on the bottom.</div>
</wds-popover>
<wds-popover side="right" label="Right">
<wds-button slot="trigger" variant="outline">Right</wds-button>
<div>The panel opens on the right.</div>
</wds-popover>
</div>
`,
})
export class PopoverSideDemo {}Align#
align aligns the panel with the start, center (default) or end of the trigger (in right-to-left text start is the right edge). --wds-popover-width sets the width of the panel (default 18rem).
import { Component } from '@angular/core';
import { WdsPopoverComponent } from '@wds/angular/popover';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-popover-align-demo',
imports: [WdsPopoverComponent, WdsButtonComponent],
template: `
<div class="flex flex-wrap gap-2">
<wds-popover align="start" label="Start" class="[--wds-popover-width:10rem]">
<wds-button slot="trigger" variant="outline">Start</wds-button>
<div>Aligned to the start.</div>
</wds-popover>
<wds-popover align="center" label="Center" class="[--wds-popover-width:10rem]">
<wds-button slot="trigger" variant="outline">Center</wds-button>
<div>Aligned to the center.</div>
</wds-popover>
<wds-popover align="end" label="End" class="[--wds-popover-width:10rem]">
<wds-button slot="trigger" variant="outline">End</wds-button>
<div>Aligned to the end.</div>
</wds-popover>
</div>
`,
})
export class PopoverAlignDemo {}User profile#
label names the panel.
import { Component } from '@angular/core';
import { WdsPopoverComponent } from '@wds/angular/popover';
import { WdsButtonComponent } from '@wds/angular/button';
import { WdsAvatarComponent } from '@wds/angular/avatar';
import { WdsBadgeComponent } from '@wds/angular/badge';
@Component({
selector: 'app-popover-profile-demo',
imports: [WdsPopoverComponent, WdsButtonComponent, WdsAvatarComponent, WdsBadgeComponent],
template: `
<wds-popover align="start" label="Mira Stone">
<wds-button slot="trigger" variant="ghost" class="gap-2">
<wds-avatar size="sm" src="https://github.com/octocat.png">MS</wds-avatar>
Mira Stone
</wds-button>
<div class="flex items-start gap-3">
<wds-avatar size="lg" src="https://github.com/octocat.png">MS</wds-avatar>
<div class="grid min-w-0 gap-0.5">
<span class="font-medium">Mira Stone</span>
<span class="truncate text-muted-foreground">mira@example.com</span>
<wds-badge variant="secondary" class="mt-1 w-fit">Admin</wds-badge>
</div>
</div>
<div class="text-muted-foreground">Product designer in the Growth team. Based in Lisbon, works 9:00–17:00 WET.</div>
<div class="grid grid-cols-2 gap-2">
<wds-button variant="outline" size="sm">Message</wds-button>
<wds-button size="sm" href="#">View profile</wds-button>
</div>
</wds-popover>
`,
})
export class PopoverProfileDemo {}Settings#
import { Component } from '@angular/core';
import { WdsPopoverComponent } from '@wds/angular/popover';
import { WdsButtonComponent } from '@wds/angular/button';
import { WdsSwitchComponent } from '@wds/angular/switch';
@Component({
selector: 'app-popover-settings-demo',
imports: [WdsPopoverComponent, WdsButtonComponent, WdsSwitchComponent],
template: `
<wds-popover heading="Notifications" description="Choose what you hear about." align="end">
<wds-button slot="trigger" variant="outline" size="icon" label="Notification settings">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.268 21a2 2 0 0 0 3.464 0" /><path d="M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326" /></svg>
</wds-button>
<div class="grid gap-3">
<wds-switch checked>Comments</wds-switch>
<wds-switch checked>Mentions</wds-switch>
<wds-switch>Weekly summary</wds-switch>
</div>
</wds-popover>
`,
})
export class PopoverSettingsDemo {}Autofocus#
autofocus gets focus when the panel opens, here the field with the link. Without it, focus goes to the panel, and Tab moves to its first control.
import { Component } from '@angular/core';
import { WdsPopoverComponent } from '@wds/angular/popover';
import { WdsButtonComponent } from '@wds/angular/button';
import { WdsInputComponent } from '@wds/angular/input';
@Component({
selector: 'app-popover-share-demo',
imports: [WdsPopoverComponent, WdsButtonComponent, WdsInputComponent],
template: `
<wds-popover heading="Share link" description="Anyone with the link can view this document." align="start">
<wds-button slot="trigger">Share</wds-button>
<div class="flex gap-2">
<wds-input class="flex-1" aria-label="Link" value="https://example.com/d/q4-report" readonly autofocus></wds-input>
<wds-button variant="outline">Copy</wds-button>
</div>
</wds-popover>
`,
})
export class PopoverShareDemo {}API References#
wds-popover#
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| open | boolean | false | show(), close() and toggle(). |
| side | WdsPopoverSide | 'bottom' | |
| align | WdsPopoverAlign | 'center' | |
| offset | number | 4 | |
| heading | string | '' | |
| description | string | '' | aria-describedby. |
| label | string | undefined | heading. | |
| disabled | boolean | false |
Events
| Event | Description |
|---|---|
| wds-open-changeCustomEvent<WdsPopoverOpenChangeDetail> |
Methods
| Method | Description |
|---|---|
| show() | |
| close() | |
| toggle() |
Slots
| Slot | Description |
|---|---|
| trigger | wds-button). It gets aria-haspopup="dialog" and aria-expanded. |
| (default) | autofocus gets focus when the panel opens; otherwise the panel itself. |
CSS parts (::part)
| Part | Description |
|---|---|
| content | |
| header | |
| title | |
| description |
CSS custom properties
| Property | Description |
|---|---|
| --wds-popover-width |
Accessibility#
Screen reader#
role="dialog") named by heading or label; description is linked with aria-describedby.
aria-haspopup="dialog" and aria-expanded; wds-button forwards them to its native button.
Keyboard support#
| Key | Function |
|---|---|