Keyboard Focus

The cxFocus directive manages keyboard-specific focus features in composable storefront, ensuring accessibility for keyboard-only users.

The cxFocus directive handles keyboard-specific features in composable storefront related to focus management. These features are essential for keyboard-only users.

The keyboard features are used for a host element, and for the focusable elements of the inner DOM of the host element. Focusable elements are HTML elements that receive focus when you use the keyboard. For example, by tabbing through the experience, focusable elements are highlighted and provide access to key features, such as "open product", "add to cart", and so on.

There are many keyboard focus features. While most of these features work in isolation, there is often a correlation between them. This is why all features are handled by a single cxFocus directive. The directive ensures that the features do not conflict, and that they work well together.

The various features of the cxFocus directive are documented separately, as follows:
Feature Description

Visible Focus

Limits the visible focus to keyboard users only.

Persist Focus

Refocuses an element based on its last focus state.

Escape Focus

Traps the focus of an element when the user presses the ESC key.

Auto Focus

Provides auto focus in a single-page experience.

Trap Focus

Traps the focus of a group of focusable elements, so that focus returns to the first element after leaving the last element.

Lock Focus

Locks and unlocks the focus of the focusable child elements of the host element.

All features have separate configuration typings, but all configurations are accessible through the FocusConfig.

The various features can be used with a single directive. The following is an example:

<div
  [cxFocus]="{
    autofocus: 'input[submit:true]',
    lock: true,
    trap: true }"
></div>