# Popover

A **popover** is a temporary overlay that displays above other content when users activate a trigger element.

## Usage

Popovers are used for brief, contextual information or temporary functionality that requires little screen space. They appear when users select a specific control or interactive area and automatically close when users select outside of them or complete an action within the popover.

![Popover](<../images/popover.png>)

### When to use

- To provide short, contextual information or additional functionality related to a control.
- For temporary content that doesn’t require a full page or modal view.
- To provide contextual help, guiding users with explanations or assistance specific to their current task.

### Best practices

- Limit functionality to a few related tasks or brief information.
- Avoid placing critical actions or decisions within a popover.
- Display only one popover at a time.
- Popovers should be just large enough to accommodate their content.

## Design

### Elements

![Popover elements](<../images/popover-elements.png>)

> 1. Container, 2. Title (optional), 3. Body content, 4. Tip

### Placement

Four position options are available: **top**, **end**, **bottom** and **start**. Besides that, **auto** option may be used to detect a position that fits the component on the screen. They should not cover too much of the screen or obscure important content.

![Popover placement](<../images/popover-placement.png>)

### Content

Popovers can include text, links, buttons, and other interactive elements relevant to the task at hand.

![Popover content](<../images/popover-content.png>)

### Tooltips vs. popovers

[Tooltips](<https://element.siemens.io/components/status-notifications/tooltip/>) are meant for supplementary, non-essential information. They’re limited to brief, non-interactive text and **appear on hover**, making them inaccessible on touch devices.

Popovers provide more comprehensive contextual information or functionality. They open upon **user selection**.

| Component | Tooltip | Popover |
| --- | --- | --- |
| **Purpose** | Provides supplementary, non-essential information. | Displays contextual information or interactive elements. |
| **Interaction** | Appears on **hover**. | Opens on **selection**. |
| **Dismissal** | Disappears when the cursor moves away. | Requires user interaction to close. |
| **Interactivity** | Non-interactive, only displays text. | Can contain buttons, links, and inputs. |

## Code

The `si-popover` is meant to hold contextual content for a specific element. It is implemented as a `role="dialog"`, thus following a common pattern for such elements.

### Popover trigger

The `siPopover` directive must always be attached to a `button`, the so-called trigger. A popover trigger MUST NOT have any other actions attached to it. The trigger button must have a descriptive label, such as `More information about component xyz`. Do not provide generic labels like `more` or `here` as users may tab through the page without reading the context.

Use the `siPopover` directive to create a popover trigger.

```
<button siPopover="..." type="button" class="btn btn-secondary">
  More information about component xyz
</button>
```

### Popover content

A popover always has a body and a title. A popover will receive the `focus` when it's opened and the focus will be returned to the trigger when it's closed. So the content may contain interactive elements, such as links or buttons.

The content can be provided in the following ways:

- using the inputs `siPopover` and `siPopoverTitle`

```
<button
  siPopover="Details Lorem ipsum ..."
  siPopoverTitle="Component xyz"
  type="button"
  class="btn btn-secondary"
>
  More information about component xyz
</button>
```

- using a template

```
<button siPopover="popoverContent" type="button" class="btn btn-secondary">
  More information about component xyz
</button>
<ng-template #popoverContent>
  <si-popover-title>Component xyz</si-popover-title>
  <si-popover-body> Details Lorem ipsum ... </si-popover-body>
</ng-template>
```

- using a template and the title input

```
<button
  siPopover="popoverContent"
  siPopoverTitle="Component xyz"
  type="button"
  class="btn btn-secondary"
  >More information about component xyz</button
>
<ng-template #popoverContent>
  <!-- If siPopoverTitle is set, the content must NOT be wrapped in a si-popover-body element. -->
  Details Lorem ipsum ...
</ng-template>
```

### Container styling

Use `siPopoverContainerClass` to add custom CSS classes to the popover container. Element also provides two built-in classes:

- `.auto-width`: Removes the default max-width limit so the popover grows to fit its content.
- `.no-content-padding`: Removes the default body padding, which is useful when placing lists, tables, or other full-width content.

These classes can be used individually or combined:

```
<button
  [siPopover]="popoverContent"
  siPopoverContainerClass="auto-width no-content-padding"
  type="button"
  class="btn btn-secondary"
>
  More information about component xyz
</button>
```

### Usage

Add the required imports to your component:

```
import {
  SiPopoverDirective,
  SiPopoverTitleDirective,
  SiPopoverBodyDirective
} from '@siemens/element-ng/popover';

@Component({
  imports: [SiPopoverDirective, SiPopoverTitleDirective, SiPopoverBodyDirective, ...]
})
```

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, inject } from '@angular/core';
import { SiIconComponent } from '@siemens/element-ng/icon';
import { LOG_EVENT } from '@siemens/live-preview';

import {
  SiPopoverDirective,
  SiPopoverTitleDirective,
  SiPopoverBodyDirective
} from '../../../../projects/element-ng/popover';

@Component({
  selector: 'app-sample',
  imports: [SiIconComponent, SiPopoverDirective, SiPopoverTitleDirective, SiPopoverBodyDirective],
  templateUrl: './si-popover.html'
})
export class SampleComponent {
  logEvent = inject(LOG_EVENT);

  myContext = {
    $implicit: {
      state: 'powered on',
      duration: '5 minutes',
      power: '1000 W',
      icon: 'element-microwave-on'
    }
  };
}
```

Template:

```html
<div
  class="button-container d-flex flex-wrap gap-4"
  style="padding-block: 120px 0; padding-inline: 80px 0"
>
  <button
    type="button"
    class="btn btn-secondary"
    siPopover="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."
    siPopoverTitle="Popover on top"
    siPopoverPlacement="top"
    (shown)="logEvent('Popover visible')"
    (hidden)="logEvent('Popover hidden')"
  >
    Popover on top
  </button>

  <button
    type="button"
    class="btn btn-secondary"
    siPopover="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."
    siPopoverTitle="Popover on end"
    siPopoverPlacement="end"
  >
    Popover on end
  </button>

  <button
    type="button"
    class="btn btn-secondary"
    siPopover="Vivamus sagittis."
    siPopoverTitle="Popover auto"
    siPopoverPlacement="auto"
    siPopoverIcon="element-info"
  >
    Popover auto
  </button>

  <button
    type="button"
    class="btn btn-secondary"
    siPopover="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."
    siPopoverTitle="Popover on start"
    siPopoverPlacement="start"
  >
    Popover on start
  </button>

  <button
    type="button"
    class="btn btn-secondary"
    siPopover="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."
    siPopoverTitle="Popover on bottom"
    siPopoverPlacement="bottom"
  >
    Popover on bottom
  </button>

  <button
    type="button"
    class="btn btn-secondary"
    siPopoverPlacement="bottom"
    [siPopover]="popoverTemplate"
  >
    Popover with template
  </button>

  <button
    type="button"
    class="btn btn-secondary"
    siPopoverPlacement="top"
    [siPopover]="popoverTemplateWithContext"
    [siPopoverContext]="myContext"
  >
    Popover with template and context
  </button>
</div>

<ng-template #popoverTemplate>
  <si-popover-title class="d-flex align-items-center gap-2">
    <si-icon class="si-display" icon="element-light-desk-filled" />
    <div>
      <strong>Hello, I'm the popover title</strong>
      <div class="text-secondary mt-1">si-popover-next-title</div></div
    >
  </si-popover-title>

  <si-popover-body>
    <div>Vivamus sagittis lacus vel augue laoreet rutrum faucibus.</div>
    <button type="button" class="btn btn-link mt-4 d-block">
      <span
        >Action link<i aria-hidden="true" class="link-icon link-end element-right-2 flip-rtl"></i
      ></span>
    </button>

    <button type="button" class="btn btn-secondary mt-6 w-100">Confirm</button>
  </si-popover-body>
</ng-template>

<ng-template #popoverTemplateWithContext let-data>
  <si-popover-title>
    <strong>Hello, I'm a microwave</strong>
  </si-popover-title>

  <si-popover-body>
    And I'm {{ data.state }} with {{ data.power }} for {{ data.duration }}.
    <button type="button" class="btn btn-link mt-4 d-block">
      <span
        >Action link<i aria-hidden="true" class="link-icon link-end element-right-2 flip-rtl"></i
      ></span>
    </button>
  </si-popover-body>
</ng-template>
```

### [SiPopoverDirective](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L40-L217>)

**Kind:** directive

**Selector:** `[siPopover]`

**Exported as:** `si-popover`

```
import { SiPopoverDirective } from '@siemens/element-ng/popover';
```

```
directive SiPopoverDirective implements OnDestroy
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [id](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L123-L123>) | `string` | `` `__popover-trigger_${this.popoverCounter}` `` | The ID of the trigger element. |
| [siPopover](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L46-L46>) | `TranslatableString \| TemplateRef<unknown> \| undefined` |  | The popover text to be displayed |
| [siPopoverContainerClass](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L80-L80>) | `string` | `''` | The class that will be applied to container of the popover |
| [siPopoverContext](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L94-L94>) | `unknown` | `undefined` | The context for the attached template |
| [siPopoverIcon](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L87-L87>) | `string \| undefined` | `undefined` | The icon to be displayed besides popover title |
| [siPopoverPlacement](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L53-L53>) | `"start" \| "end" \| "bottom" \| "auto" \| "top"` | `'auto'` | The placement of the popover. One of 'top', 'start', 'end', 'bottom' |
| [siPopoverScrollStrategy](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L101-L103>) | `ScrollStrategy` | `defaultConnectedOverlayScrollStrategy()` | CDK scroll strategy used for the popover overlay. |
| [siPopoverTitle](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L73-L73>) | `TranslatableString \| undefined` | `undefined` | The title to be displayed on top for the popover |

#### Output Properties

| Name | Type | Description |
| --- | --- | --- |
| [siPopoverVisibilityChange](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L108-L108>) | `boolean` | Emits `true` when the popover is shown, `false` when the popover is hidden. |

#### Attributes and Methods

##### hide

[Source for hide](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L162-L164>)

Hides the popover and emits 'hidden' event.

```
hide(): void
```

**Returns:** [void](<https://www.typescriptlang.org/docs/handbook/2/functions.html#void>)

##### placementInternal

[Source for placementInternal](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L55-L66>)

**Modifiers:** readonly

**Type:** `Signal<"start" | "end" | "bottom" | "auto" | "top">`

**Default:** `...`

##### show

[Source for show](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L143-L157>)

Displays popover and emits 'shown' event.

```
show(): void
```

**Returns:** [void](<https://www.typescriptlang.org/docs/handbook/2/functions.html#void>)

##### updatePosition

[Source for updatePosition](<https://github.com/siemens/element/blob/main/projects/element-ng/popover/si-popover.directive.ts#L169-L171>)

Updates the position of the popover based on the position strategy.

```
updatePosition(): void
```

**Returns:** [void](<https://www.typescriptlang.org/docs/handbook/2/functions.html#void>)

### Types Documentation

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```
