Lint Rules

noAutofocus (since v10.0.0)

This rule is recommended by Rome.

Avoid the autoFocus attribute

Examples

Invalid

<input autoFocus />
a11y/noAutofocus.js:1:8 lint/a11y/noAutofocus  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Avoid the autoFocus attribute.
  
  > 1 │ <input autoFocus />
          ^^^^^^^^^
    2 │ 
  
   Suggested fix: Remove the autoFocus attribute.
  
    1 │ <input·autoFocus·/>
         ----------  
<input autoFocus="true" />
a11y/noAutofocus.js:1:8 lint/a11y/noAutofocus  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Avoid the autoFocus attribute.
  
  > 1 │ <input autoFocus="true" />
          ^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Remove the autoFocus attribute.
  
    1 │ <input·autoFocus="true"·/>
         -----------------  
<input autoFocus={"false"} />
a11y/noAutofocus.js:1:8 lint/a11y/noAutofocus  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Avoid the autoFocus attribute.
  
  > 1 │ <input autoFocus={"false"} />
          ^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Remove the autoFocus attribute.
  
    1 │ <input·autoFocus={"false"}·/>
         --------------------  
<input autoFocus={undefined} />
a11y/noAutofocus.js:1:8 lint/a11y/noAutofocus  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Avoid the autoFocus attribute.
  
  > 1 │ <input autoFocus={undefined} />
          ^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Remove the autoFocus attribute.
  
    1 │ <input·autoFocus={undefined}·/>
         ----------------------  

Valid

<input />
<div />
<button />
// `autoFocus` prop in user created component is valid
<MyComponent autoFocus={true} />