Linter Rule: No autofocus attribute
Rule: a11y-no-autofocus-attribute
Description
Prevent usage of the autofocus attribute on HTML elements, Action View Form Tag Helpers and Action View Form Builder methods.
Rationale
The autofocus attribute is a global attribute that indicates an element should be focused on page load. It reduces accessibility by moving users to an element without warning and context.
Its use should be limited to form fields that serve as the main purpose of the page, such as a search input on a search page.
Examples
✅ Good
erb
<input type="text">erb
<%= text_field_tag :name, "value" %>erb
<%= f.text_field :name %>🚫 Bad
erb
<input type="text" autofocus>erb
<input type="password" autofocus="autofocus">erb
<%= text_field_tag :name, "value", autofocus: true %>erb
<%= f.text_area :body, autofocus: true %>