Skip to content
← Back to rules

jsx-a11y/aria-unsupported-elements 正确性

🛠️ An auto-fix is available for this rule.

作用

强制规定保留的 DOM 元素不得包含 ARIA 角色、状态 或属性。

为什么这不好?

某些保留的 DOM 元素不支持 ARIA 角色、状态和 属性。这通常是因为它们不可见,例如 metahtmlscriptstyle。向这些 元素添加 ARIA 属性没有意义,并且可能会给屏幕阅读器带来困惑。

示例

以下是此规则的错误代码示例:

jsx
<meta charset="UTF-8" aria-hidden="false" />

以下是此规则的正确代码示例:

jsx
<meta charset="UTF-8" />

如何使用

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

json
{
  "plugins": ["jsx-a11y"],
  "rules": {
    "jsx-a11y/aria-unsupported-elements": "error"
  }
}
ts
import { defineConfig } from "oxlint";

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

版本

此规则在 v0.1.1 中添加。

参考资料