Skip to content
← Back to rules

jsx-a11y/role-has-required-aria-props Correctness

作用

强制具有 ARIA 角色的元素必须拥有该角色所需的全部属性。

为什么这不好?

某些 ARIA 角色需要特定属性,以向辅助技术表达必要的语义。

示例

此规则的错误代码示例:

jsx
<div role="checkbox" />

此规则的正确代码示例:

jsx
<div role="checkbox" aria-checked="false" />

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["jsx-a11y"],
  "rules": {
    "jsx-a11y/role-has-required-aria-props": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["jsx-a11y"],
  rules: {
    "jsx-a11y/role-has-required-aria-props": "error",
  },
});
bash
oxlint --deny jsx-a11y/role-has-required-aria-props --jsx-a11y-plugin

版本

此规则在 v0.2.0 中添加。

参考资料