Skip to content

useAriaActivedescendantWithTabindex

诊断类别:lint/a11y/useAriaActivedescendantWithTabindex

¥Diagnostic Category: lint/a11y/useAriaActivedescendantWithTabindex

自从:v1.3.0

¥Since: v1.3.0

来源:

¥Sources:

强制 tabIndex 元素具有 aria-activedescendant 属性。

¥Enforce that tabIndex is assigned to non-interactive HTML elements with aria-activedescendant.

aria-activedescendant 用于管理 复合小部件 内的焦点。具有属性 aria-activedescendant 的元素保留活动文档焦点。

¥aria-activedescendant is used to manage to focus within a composite widget. The element with the attribute aria-activedescendant retains the active document focus.

它通过将该元素的 ID 分配给 aria-activedescendant 的值来指示其子元素中的哪个具有次要焦点。此模式用于构建小部件,如搜索输入选择列表。搜索输入框保留文档焦点,以便用户可以输入内容。如果按下向下箭头键并高亮搜索建议,则建议元素的 ID 将作为输入元素上 aria-activedescendant 的值应用。

¥It indicates which of its child elements has a secondary focus by assigning the ID of that element to the value of aria-activedescendant. This pattern is used to build a widget like a search typeahead select list. The search input box retains document focus so that the user can type in the input. If the down arrow key is pressed and a search suggestion is highlighted, the ID of the suggestion element will be applied as the value of aria-activedescendant on the input element.

因为具有 aria-activedescendant 的元素必须是可制表的,所以它必须具有固有的 tabIndex 为零或声明 tabIndex 属性。

¥Because an element with aria-activedescendant must be tabbable, it must either have an inherent tabIndex of zero or declare a tabIndex attribute.

¥Examples

¥Invalid

<div aria-activedescendant={someID} />
code-block.jsx:1:1 lint/a11y/useAriaActivedescendantWithTabindex  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

Enforce elements with aria-activedescendant are tabbable.

> 1 │ <div aria-activedescendant={someID} />
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

aria-activedescendant is used to manage focus within a composite widget.
The element with the attribute aria-activedescendant retains the active document focus.

Add the tabIndex attribute to the element with a value greater than or equal to -1.

Unsafe fix: Add the tabIndex attribute.

1 │ <div·aria-activedescendant={someID}··tabIndex=0·/>
++++++++++++++

¥Valid

<div aria-activedescendant={someID} tabIndex={0} />
<input aria-activedescendant={someID} />

¥Related links