Utilities
The Focus Trap utility is a directive that traps focus within a specified element. This is useful for modals, dropdowns, and other components that require focus to be contained within a specific area.
<div [ngpFocusTrapDisabled]="disabled()" ngpFocusTrap>
<button (click)="disabled.set(false)" ngpButton>Enable Focus Trap</button>
<button (click)="disabled.set(true)" ngpButton>Disable Focus Trap</button>
</div>
Import the FocusTrap primitives from ng-primitives/focus-trap
.
import { NgpFocusTrap } from 'ng-primitives/focus-trap';
Assemble the focus-trap directives in your template.
<div ngpFocusTrap></div>
The following directives are available to import from the ng-primitives/focus-trap
package:
The NgpFocusTrap
directive traps focus within the host element.
[ngpFocusTrap]
ngpFocusTrap
Disables the focus trap.
Attribute | Description |
---|---|
data-focus-trap |
Applied when focus is trapped. |
Adheres to the WAI-ARIA design pattern.
Copyright © 2025 Angular Primitives