jsx-a11y/iframe-has-title Correctness
它的作用
强制 iframe 元素具有 title 属性。
为什么这不好?
屏幕阅读器用户依赖 iframe 的 title 来描述 iframe 的内容。 如果标记中不包含 title 属性,对于这类技术的用户来说,快速在 iframe 和 iframe 元素之间导航会变得困难且令人困惑。
示例
以下是此规则的错误代码示例:
jsx
<iframe />
<iframe {...props} />
<iframe title="" />
<iframe title={''} />
<iframe title={``} />
<iframe title={undefined} />
<iframe title={false} />
<iframe title={true} />
<iframe title={42} />以下是此规则的正确代码示例:
jsx
<iframe title="This is a unique title" />
<iframe title={uniqueTitle} />如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["jsx-a11y"],
"rules": {
"jsx-a11y/iframe-has-title": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["jsx-a11y"],
rules: {
"jsx-a11y/iframe-has-title": "error",
},
});bash
oxlint --deny jsx-a11y/iframe-has-title --jsx-a11y-plugin版本
此规则添加于 v0.0.19。
