a11y/interactive-supports-focus
要求具有交互角色的元素可获得焦点。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, opinionated |
不支持 | 无 |
适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。
与 eslint-plugin-vuejs-accessibility 不同,拥有可聚焦 option 的 listbox(roving tabindex)或由 combobox 通过 aria-activedescendant 控制的 listbox 本身不需要 Tab 停靠点;所有条件分支都是整数的 tabindex 绑定(:tabindex="active ? 0 : -1")视为 tabindex;:aria-hidden="false" 不会隐藏元素。
错误示例
为 span 设置按钮角色和点击处理器,并不会让它能够通过键盘获得焦点。
<template>
<span role="button" @click="open">Open</span>
</template>
正确示例
原生按钮可以获得焦点,并保留同一 open 操作。
<template>
<button type="button" @click="open">Open</button>
</template>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"a11y/interactive-supports-focus": "warn"
}
},
});
然后运行 vp run lint。