Primitives
Display arbitrary content inside floating panels.
Import the Popover primitives from ng-primitives/popover.
import { NgpPopover, NgpPopoverTrigger, NgpPopoverArrow } from 'ng-primitives/popover';
Assemble the popover directives in your template.
<button [ngpPopoverTrigger]="popover" (ngpPopoverTriggerOpenChange)="onPopoverStateChange($event)">
Click me
</button>
<ng-template #popover>
<div ngpPopover>Popover content</div>
</ng-template>
You can listen to the ngpPopoverTriggerOpenChange event to perform actions when the popover state changes. The event emits a boolean value indicating whether the popover is open or closed:
You can customize the offset using either a simple number or an object for more precise control:
<!-- Simple number offset -->
<button [ngpPopoverTrigger]="popover" ngpPopoverTriggerOffset="12">Popover with 12px offset</button>
<!-- Object offset for precise control -->
<button
[ngpPopoverTrigger]="popover"
[ngpPopoverTriggerOffset]="{mainAxis: 8, crossAxis: 4, alignmentAxis: 2}"
>
Popover with custom offset
</button>
You can customize the shift behavior to control how the popover stays within the viewport:
<!-- Disable shift -->
<button [ngpPopoverTrigger]="popover" [ngpPopoverTriggerShift]="false">
Popover without shift
</button>
<!-- Object shift for precise control -->
<button [ngpPopoverTrigger]="popover" [ngpPopoverTriggerShift]="{padding: 8}">
Popover with custom shift padding
</button>
Create a popover component that uses the NgpPopover directive.
Generate a reusable tooltip component using the Angular CLI.
ng g ng-primitives:primitive popover
path: The path at which to create the component file.prefix: The prefix to apply to the generated component selector.componentSuffix: The suffix to apply to the generated component class name.fileSuffix: The suffix to apply to the generated component file name. Defaults to component.exampleStyles: Whether to include example styles in the generated component file. Defaults to trueThe popover can be anchored to a different element than the trigger.
The following directives are available to import from the ng-primitives/popover package:
| Attribute | Description |
|---|---|
data-enter |
Applied when the popover is being added to the DOM. This can be used to trigger animations. |
data-exit |
Applied when the popover is being removed from the DOM. This can be used to trigger animations. |
data-placement |
The final rendered placement of the popover. |
The following CSS custom properties are applied to the ngpPopover directive:
| Property | Description |
|---|---|
--ngp-popover-transform-origin |
The transform origin of the popover for animations. |
--ngp-popover-trigger-width |
The width of the trigger element. |
| Attribute | Description |
|---|---|
data-open |
Applied when the popover is open. |
data-disabled |
Applied when the popover is disabled. |
The NgpPopoverArrow directive is used to add an arrow to the popover. It should be placed inside the popover content. It will receive inset-inline-start or inset-block-start styles to position the arrow based on the popover's placement. As a result it should be positioned absolutely within the popover content.
The arrow can be styled conditionally based on the popover's final placement using the data-placement attribute:
[ngpPopoverArrow][data-placement='top'] {
/* Arrow styles when popover is positioned on top */
}
[ngpPopoverArrow][data-placement='bottom'] {
/* Arrow styles when popover is positioned on bottom */
}
| Attribute | Description |
|---|---|
data-placement |
The final rendered placement of the popover. |
For the popover to be positioned correctly relative to the trigger element, it must use absolute or fixed positioning. For example, you can use the following CSS:
[ngpPopover] {
position: absolute;
}
The ngpPopover primitive adds a CSS custom property --ngp-popover-transform-origin to the element that can be used to animate the popover from the trigger element.
The ngpPopover will also add the data-enter and data-exit attributes to the element when it is being added or removed from the DOM. This can be used to trigger animations.
:host[data-enter] {
animation: fade-in 0.2s ease-in-out;
}
:host[data-exit] {
animation: fade-out 0.2s ease-in-out;
}
You can configure the default options for all popovers in your application by using the providePopoverConfig function in a providers array.
import { providePopoverConfig } from 'ng-primitives/popover';
bootstrapApplication(AppComponent, {
providers: [
providePopoverConfig({
offset: 4,
placement: 'top',
showDelay: 0,
hideDelay: 0,
flip: true,
container: document.body,
closeOnOutsideClick: true,
scrollBehavior: 'reposition',
}),
],
});
Number format: offset: 8 - Applies to mainAxis (distance from trigger)
Object format:
offset: {
mainAxis: 8, // Distance between popover and trigger element
crossAxis: 4, // Skidding along the alignment axis
alignmentAxis: 2 // Same as crossAxis but for aligned placements
}
Boolean format: shift: false - Disables shift behavior
Object format:
shift: {
padding: 8, // Minimum padding between popover and viewport edges
limiter: { // Optional limiter to control shifting behavior
fn: limitShift,
options: { /* limiter options */ }
}
}
Copyright © 2026 Angular Primitives
This site is powered by Netlify