jsx-a11y/no-interactive-element-to-noninteractive-role 正确性
它的作用
交互式 HTML 元素表示用户界面中的控件。交互式元素包括 <a href>、<button>、<input>、<select>、<textarea>。
不应使用 WAI-ARIA 角色将交互式元素转换为非交互式元素。 非交互式 ARIA 角色包括 article、banner、complementary、img、listitem、main、region 和 tooltip。
为什么这不好?
在交互式元素上使用非交互式角色可能会使辅助技术用户感到困惑。
示例
以下是此规则的错误代码示例:
jsx
<button role="img">保存</button>以下是此规则的正确代码示例:
jsx
<div role="img">
<button>保存</button>
</div>配置
此规则接受一个具有以下属性的配置对象:
type: object
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["jsx-a11y"],
"rules": {
"jsx-a11y/no-interactive-element-to-noninteractive-role": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["jsx-a11y"],
rules: {
"jsx-a11y/no-interactive-element-to-noninteractive-role": "error",
},
});bash
oxlint --deny jsx-a11y/no-interactive-element-to-noninteractive-role --jsx-a11y-plugin版本
此规则已在 v1.65.0 中添加。
