noAutofocus
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
¥Diagnostic Category:
lint/a11y/noAutofocus -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
¥Same as
jsx-a11y/no-autofocus
-
¥How to configure
{ "linter": { "rules": { "a11y": { "noAutofocus": "error" } } }}¥Description
强制元素上未使用 autoFocus prop。
¥Enforce that autoFocus prop is not used on elements.
自动聚焦元素可能会给视力正常和视力不佳的用户带来可用性问题。在打开模态对话框或弹出窗口时,应立即将 autofocus 属性添加到用户预期与之交互的元素上。
¥Autofocusing elements can cause usability issues for sighted and non-sighted users, alike. But the autofocus attribute should be added to the element the user is expected to interact with immediately upon opening a modal dialog or popover.
¥Examples
¥Invalid
<input autoFocus />code-block.jsx:1:8 lint/a11y/noAutofocus FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid the autoFocus attribute.
> 1 │ <input autoFocus />
│ ^^^^^^^^^
2 │
ℹ Unsafe fix: Remove the autoFocus attribute.
1 │ <input·autoFocus·/>
│ ----------
<input autoFocus="true" />code-block.jsx:1:8 lint/a11y/noAutofocus FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid the autoFocus attribute.
> 1 │ <input autoFocus=“true” />
│ ^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Remove the autoFocus attribute.
1 │ <input·autoFocus=“true”·/>
│ -----------------
<input autoFocus={"false"} />code-block.jsx:1:8 lint/a11y/noAutofocus FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid the autoFocus attribute.
> 1 │ <input autoFocus={“false”} />
│ ^^^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Remove the autoFocus attribute.
1 │ <input·autoFocus={“false”}·/>
│ --------------------
<input autoFocus={undefined} />code-block.jsx:1:8 lint/a11y/noAutofocus FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid the autoFocus attribute.
> 1 │ <input autoFocus={undefined} />
│ ^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Remove the autoFocus attribute.
1 │ <input·autoFocus={undefined}·/>
│ ----------------------
¥Valid
<input /><div /><button />// `autoFocus` prop in user created component is valid<MyComponent autoFocus={true} />// `autoFocus` prop in element has `popover` attribute is valid<div popover><input autoFocus /></div>// `autoFocus` prop in `dialog` is valid<dialog><input autoFocus /></dialog>¥Resources
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号