jsx-a11y/no-autofocus
Disallow the autoFocus prop — stolen focus disorients screen-reader and keyboard users.
- Category: Accessibility
- Severity: warn
- Source:
oxlint-builtin:jsx-a11y - Framework: global
- Enabled when: always (unless customRulesOnly=true)
- Documentation: https://oxc.rs/docs/guide/usage/linter/rules/jsx_a11y/no-autofocus
Validate the diagnostic
Confirm the reported code matches this rule before you edit it.
Fires on any JSX element with the autoFocus prop set to anything other than false (so autoFocus, autoFocus={true}, and autoFocus={undefined} all trigger). By default both DOM elements and custom components are checked; ignoreNonDOM: true skips PascalCase components. False positive: a modal/dialog where focus must move to a specific element on open as part of intentional focus management.
How to fix
Follow the rule guidance while preserving unrelated behavior.
Copyable fix prompt
Copy this self-contained prompt into your coding agent after you confirm the diagnostic.
Remove the autoFocus prop. If focus must move on mount (e.g. when a dialog opens), use a ref + useEffect to call .focus() imperatively only in that scenario, or rely on a focus-trap library that respects user context. Auto-focus on page load disorients screen reader users and steals focus before they finish reading prior content. See https://oxc.rs/docs/guide/usage/linter/rules/jsx_a11y/no-autofocus
Related rules
More Accessibility rules from the rules reference:
react-doctor/alt-text: Require alternative text on img, area, input[type='image'], and object elements so screen readers can describe them.react-doctor/anchor-ambiguous-text: Describe a link's destination — avoid bare 'click here' / 'learn more' / 'link' as the only link text.react-doctor/anchor-has-content: Add visible or aria-labelled text inside every `<a>`.react-doctor/anchor-is-valid: Require anchors to navigate to a real destination — use a button for click-only actions instead of href='#' or javascript:void(0).react-doctor/aria-activedescendant-has-tabindex: Add `tabIndex` to elements with `aria-activedescendant` so they're keyboard-focusable.