- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Trace
Popover
Displays rich content in a portal, triggered by a button.
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmInputImports } from '@spartan-ng/helm/input';
import { HlmLabelImports } from '@spartan-ng/helm/label';
import { HlmPopoverImports } from '@spartan-ng/helm/popover';
@Component({
selector: 'spartan-popover-preview',
imports: [HlmPopoverImports, HlmButtonImports, HlmLabelImports, HlmInputImports],
template: `
<hlm-popover sideOffset="5">
<button hlmPopoverTrigger hlmBtn variant="outline">Open Popover</button>
<hlm-popover-content class="grid w-80 gap-4" *hlmPopoverPortal="let ctx">
<div class="space-y-2">
<h4 class="leading-none font-medium">Dimensions</h4>
<p class="text-muted-foreground text-sm">Set the dimensions for the layer.</p>
</div>
<div class="grid gap-2">
<div class="grid grid-cols-3 items-center gap-4">
<label hlmLabel for="width">Width</label>
<input hlmInput id="width" [defaultValue]="'100%'" class="col-span-2 h-8" />
</div>
<div class="grid grid-cols-3 items-center gap-4">
<label hlmLabel for="maxWidth">Max. width</label>
<input hlmInput id="maxWidth" [defaultValue]="'300px'" class="col-span-2 h-8" />
</div>
<div class="grid grid-cols-3 items-center gap-4">
<label hlmLabel for="height">Height</label>
<input hlmInput id="height" [defaultValue]="'25px'" class="col-span-2 h-8" />
</div>
<div class="grid grid-cols-3 items-center gap-4">
<label hlmLabel for="maxHeight">Max. height</label>
<input hlmInput id="maxHeight" [defaultValue]="'none'" class="col-span-2 h-8" />
</div>
</div>
</hlm-popover-content>
</hlm-popover>
`,
})
export class PopoverPreview {}Installation
ng g @spartan-ng/cli:ui popovernx g @spartan-ng/cli:ui popoverUsage
import { HlmPopoverImports } from '@spartan-ng/helm/popover';<hlm-popover>
<button hlmPopoverTrigger>Open Popover</button>
<hlm-popover-content *hlmPopoverPortal="let ctx"></hlm-popover-content>
</hlm-popover>Examples
Basic
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmPopoverImports } from '@spartan-ng/helm/popover';
@Component({
selector: 'spartan-popover-basic',
imports: [HlmPopoverImports, HlmButtonImports],
template: `
<hlm-popover sideOffset="5" align="start">
<button hlmPopoverTrigger hlmBtn variant="outline">Open Popover</button>
<hlm-popover-content *hlmPopoverPortal="let ctx">
<hlm-popover-header>
<div hlmPopoverTitle>Dimensions</div>
<p hlmPopoverDescription>Set the dimensions for the layer.</p>
</hlm-popover-header>
</hlm-popover-content>
</hlm-popover>
`,
})
export class PopoverBasic {}Align
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmPopoverImports } from '@spartan-ng/helm/popover';
@Component({
selector: 'spartan-popover-align',
imports: [HlmPopoverImports, HlmButtonImports],
template: `
<div class="flex gap-6">
<hlm-popover sideOffset="5" align="start">
<button hlmPopoverTrigger hlmBtn variant="outline">Start</button>
<hlm-popover-content class="w-40" *hlmPopoverPortal="let ctx">Aligned to start</hlm-popover-content>
</hlm-popover>
<hlm-popover sideOffset="5" align="center">
<button hlmPopoverTrigger hlmBtn variant="outline">Center</button>
<hlm-popover-content class="w-40" *hlmPopoverPortal="let ctx">Aligned to center</hlm-popover-content>
</hlm-popover>
<hlm-popover sideOffset="5" align="end">
<button hlmPopoverTrigger hlmBtn variant="outline">End</button>
<hlm-popover-content class="w-40" *hlmPopoverPortal="let ctx">Aligned to end</hlm-popover-content>
</hlm-popover>
</div>
`,
})
export class PopoverAlign {}Restore Focus
When the popover closes and focus is lost (for example because the focused element was removed or a non-focusable area was clicked), focus moves back to the element that was focused when it opened. This is enabled by default. Set [restoreFocus]="false" on the popover to disable it, or provide provideBrnPopoverDefaultOptions({ restoreFocus: false }) to change the default.
import { provideBrnPopoverDefaultOptions } from '@spartan-ng/brain/popover';
@Component({
providers: [provideBrnPopoverDefaultOptions({ restoreFocus: false })],
template: `<hlm-popover [restoreFocus]="false">...</hlm-popover>`,
})RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
import { Directionality } from '@angular/cdk/bidi';
import { Component, computed, effect, inject, untracked } from '@angular/core';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmInputImports } from '@spartan-ng/helm/input';
import { HlmLabelImports } from '@spartan-ng/helm/label';
import { HlmPopoverImports } from '@spartan-ng/helm/popover';
@Component({
selector: 'spartan-popover-rtl-preview',
imports: [HlmPopoverImports, HlmButtonImports, HlmLabelImports, HlmInputImports],
providers: [Directionality],
host: {
class: 'flex w-full justify-center',
'[dir]': '_dir()',
},
template: `
<hlm-popover sideOffset="5">
<button hlmPopoverTrigger hlmBtn variant="outline">{{ _t()['open'] }}</button>
<hlm-popover-content class="grid w-80 gap-4" *hlmPopoverPortal="let ctx">
<div class="space-y-2">
<h4 class="leading-none font-medium">{{ _t()['title'] }}</h4>
<p class="text-muted-foreground text-sm">{{ _t()['description'] }}</p>
</div>
<div class="grid gap-2">
<div class="grid grid-cols-3 items-center gap-4">
<label hlmLabel for="width">{{ _t()['width'] }}</label>
<input hlmInput id="width" [defaultValue]="'100%'" class="col-span-2 h-8" />
</div>
<div class="grid grid-cols-3 items-center gap-4">
<label hlmLabel for="height">{{ _t()['height'] }}</label>
<input hlmInput id="height" [defaultValue]="'25px'" class="col-span-2 h-8" />
</div>
</div>
</hlm-popover-content>
</hlm-popover>
`,
})
export class PopoverRtlPreview {
private readonly _directionality = inject(Directionality);
private readonly _language = inject(TranslateService).language;
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: {
open: 'Open popover',
title: 'Dimensions',
description: 'Set the dimensions for the layer.',
width: 'Width',
height: 'Height',
},
},
ar: {
dir: 'rtl',
values: {
open: 'افتح النافذة',
title: 'الأبعاد',
description: 'اضبط أبعاد الطبقة.',
width: 'العرض',
height: 'الارتفاع',
},
},
he: {
dir: 'rtl',
values: {
open: 'פתח חלון',
title: 'מידות',
description: 'הגדר את המידות עבור השכבה.',
width: 'רוחב',
height: 'גובה',
},
},
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
constructor() {
effect(() => {
const dir = this._dir();
untracked(() => this._directionality.valueSignal.set(dir));
});
}
}Brain API
BrnPopoverContent
Selector: [brnPopoverContent]
ExportAs: brnPopoverContent
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| class | string | null | undefined | undefined | - |
| context | T | undefined | undefined | - |
BrnPopoverTrigger
Selector: button[brnPopoverTrigger],button[brnPopoverTriggerFor]
ExportAs: brnPopoverTrigger
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| brnPopoverTriggerFor | BrnPopover | undefined | undefined | - |
| id | string | `brn-overlay-trigger-${++triggerIdSequence}` | - |
| type | 'button' | 'submit' | 'reset' | 'button' | - |
| brnOverlayTriggerFor | BrnOverlay | undefined | undefined | - |
BrnPopover
Selector: [brnPopover],brn-popover
ExportAs: brnPopover
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| align | BrnPopoverAlign | this._config.align | - |
| sideOffset | number | this._config.sideOffset | - |
| offsetX | number | this._config.offsetX | - |
| id | string | `brn-overlay-${++overlayIdSequence}` | - |
| state | BrnOverlayState | null | null | - |
| role | BrnOverlayOptions['role'] | this._defaultOptions.role | - |
| aria-modal | boolean | this._defaultOptions.ariaModal | - |
| hasBackdrop | boolean | this._defaultOptions.hasBackdrop | - |
| positionStrategy | BrnOverlayOptions['positionStrategy'] | this._defaultOptions.positionStrategy | - |
| scrollStrategy | BrnOverlayOptions['scrollStrategy'] | 'close' | 'reposition' | null | this._defaultOptions.scrollStrategy | - |
| closeOnOutsidePointerEvents | boolean | this._defaultOptions.closeOnOutsidePointerEvents | - |
| attachTo | BrnOverlayOptions['attachTo'] | this._defaultOptions.attachTo | - |
| attachPositions | BrnOverlayOptions['attachPositions'] | this._defaultOptions.attachPositions | - |
| disableClose | boolean | this._defaultOptions.disableClose | - |
| autoFocus | boolean | this._defaultOptions.autoFocus | - |
| restoreFocus | boolean | this._defaultOptions.restoreFocus | Whether to move focus back to the element that was focused when the overlay opened, if focus is lost (e.g. on `body`) when the overlay closes. |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| closed | TResult | - | - |
| stateChanged | BrnOverlayState | - | - |
Helm API
HlmPopoverContent
Selector: [hlmPopoverContent],hlm-popover-content
ExportAs: hlmPopoverContent
HlmPopoverDescription
Selector: [hlmPopoverDescription]
ExportAs: hlmPopoverDescription
HlmPopoverHeader
Selector: [hlmPopoverHeader],hlm-popover-header
ExportAs: hlmPopoverHeader
HlmPopoverPortal
Selector: [hlmPopoverPortal]
ExportAs: hlmPopoverPortal
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| context | T | undefined | undefined | - |
| class | string | null | undefined | undefined | - |
HlmPopoverTitle
Selector: [hlmPopoverTitle]
ExportAs: hlmPopoverTitle
HlmPopoverTrigger
Selector: button[hlmPopoverTrigger],button[hlmPopoverTriggerFor]
ExportAs: hlmPopoverTrigger
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | `brn-overlay-trigger-${++triggerIdSequence}` | - |
| hlmPopoverTriggerFor | BrnPopover | undefined | undefined | - |
| type | 'button' | 'submit' | 'reset' | 'button' | - |
HlmPopover
Selector: [hlmPopover],hlm-popover
ExportAs: hlmPopover
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| align | BrnPopoverAlign | this._config.align | - |
| aria-modal | boolean | this._defaultOptions.ariaModal | - |
| attachTo | BrnOverlayOptions['attachTo'] | this._defaultOptions.attachTo | - |
| autoFocus | boolean | this._defaultOptions.autoFocus | - |
| closeOnOutsidePointerEvents | boolean | this._defaultOptions.closeOnOutsidePointerEvents | - |
| offsetX | number | this._config.offsetX | - |
| restoreFocus | boolean | this._defaultOptions.restoreFocus | Whether to move focus back to the element that was focused when the overlay opened, if focus is lost (e.g. on `body`) when the overlay closes. |
| scrollStrategy | BrnOverlayOptions['scrollStrategy'] | 'close' | 'reposition' | null | this._defaultOptions.scrollStrategy | - |
| sideOffset | number | this._config.sideOffset | - |
| state | BrnOverlayState | null | null | - |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| stateChanged | BrnOverlayState | - | - |
| closed | TResult | - | - |
On This Page