Interactions
Normalizes the focus event across different browsers and devices.
Input is blurred.
Import the Focus primitives from ng-primitives/interactions.
import { NgpFocus } from 'ng-primitives/interactions';
Assemble the focus directives in your template.
<div (ngpFocus)="onFocusChange($event)"></div>
The following directives are available to import from the ng-primitives/interactions package:
This was inspired by the React Aria useFocus hook.
https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/interactions/src/useFocus.ts#L20 Whether listening for focus events is disabled.
Emit when the focus state changes.
[ngpFocus]ngpFocus
The following data attributes are applied to the ngpFocus directive:
| Attribute | Description |
|---|---|
data-focus |
Applied when the element is focused. |
Many primitives automatically add focus handling to components. If you want to disable focus handling, either globally or on a per-component/per-directive basis, you can do so by registering the provideInteractionConfig provider and setting the focus option to false.
import { provideInteractionConfig } from 'ng-primitives/interactions';
providers: [
provideInteractionConfig({
focus: false,
}),
],
Copyright © 2025 Angular Primitives