noAutofocus
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/a11y/noAutofocus
Since: v1.0.0
Sources:
- Same as:
jsx-a11y/no-autofocus
Enforce that autoFocus prop is not used on elements.
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
Section titled ExamplesInvalid
Section titled Invalidcode-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·/>
│ ----------
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”·/>
│ -----------------
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”}·/>
│ --------------------
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
Section titled ValidResources
Section titled Resources- WHATWG HTML Standard, The autofocus attribute
- The accessibility of HTML 5 autofocus
- MDN Web Docs, HTMLElement: autofocus property