Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Bug: Anchor tags do not support autoFocus | GoodFirstPicks

Bug: Anchor tags do not support autoFocus

facebook/react 4 comments 1mo ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeReactJavaScriptTypeScript

Why this is a good first issue

The issue involves modifying core React behavior to support a global attribute on anchor tags.

AI Summary

The issue requests adding `autoFocus` support for anchor tags in React, which currently only supports it for form controls. This involves modifying core React DOM handling logic and may have accessibility implications. The requirements are somewhat clear, but the implementation requires understanding React's internal DOM handling and potential browser compatibility issues.

Issue Description

Hi team!

React currently doesn't support the autoFocus prop for anchor tags. This issue has been raised before, however it was automatically marked as Stale and closed: https://github.com/facebook/react/issues/26603

My opinion matches that of the above ticket author: autofocus is a global attribute and should work for anchor tags just like it does for buttons, text inputs, etc. It sounds like this was discussed several years ago (https://github.com/facebook/react/issues/11851#issuecomment-351672131), however browser support for the autoFocus attribute has greatly matured since 2017. I'm not sure modern browsers even need the current polyfill behaviour?

React version: 18.2.0 (Same behaviour in main)

Steps To Reproduce

  1. Add an a tag with a href value and autoFocus.
  2. Observe as the anchor tag is not autofocused on page load.

Link to code example: https://codesandbox.io/p/sandbox/strange-ritchie-wc94dy

The current behavior

Anchor tags do not receive focus on page load if the autoFocus prop/attribute is used.

The expected behavior

Anchor tags do receive focus on page load if the autoFocus prop/attribute is used.

Dev Notes

The problem stems from the following switch cases where only the button, input, select and textarea inputs are supported:

  • https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js#L660
  • https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/client/ReactFib

GitHub Labels

Status: Unconfirmed

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • accessibility concerns
  • potential browser compatibility issues
Loading labels...

Details

Points10 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedno