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.
| Feature | Description |
|---|---|
|
Limits the visible focus to keyboard users only. |
|
|
Refocuses an element based on its last focus state. |
|
|
Traps the focus of an element when the user presses the ESC key. |
|
|
Provides auto focus in a single-page experience. |
|
|
Traps the focus of a group of focusable elements, so that focus returns to the first element after leaving the last element. |
|
|
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>