Interactions

Focus Visible

Determine whether focus should be visible based on user interaction. This is useful for accessibility and user experience, as it allows you to provide visual feedback when an element is focused using keyboard navigation, while not showing the focus outline when the user is using a mouse or touch device.

Import

Import the Focus Visible primitives from ng-primitives/interactions.

import { NgpFocusVisible } from 'ng-primitives/interactions';

Usage

Assemble the focus-visible directives in your template.

<div (ngpFocusVisible)="onFocusVisible($event)"></div>

API Reference

The following directives are available to import from the ng-primitives/interactions package:

NgpFocusVisible

Apply the `ngpFocusVisible` directive to an element that should be visually focused. This is similar to `ngpFocus` but it will only apply the focus visible styles when the element is focused via keyboard navigation.

  • Selector: [ngpFocusVisible]
  • Exported As: ngpFocusVisible
ngpFocusVisibleDisabled
boolean

Whether focus events are listened to.

ngpFocusVisible
boolean

Emit when the element is visually focused.

Data Attributes

The following data attributes are applied to the ngpFocusVisible directive:

Attribute Description
data-focus-visible Applied when the element is focused via keyboard navigation.

Copyright © 2025 Angular Primitives