The issue involves modifying core React behavior to support a global attribute on anchor tags.
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.
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)
a tag with a href value and autoFocus.Link to code example: https://codesandbox.io/p/sandbox/strange-ritchie-wc94dy
Anchor tags do not receive focus on page load if the autoFocus prop/attribute is used.
Anchor tags do receive focus on page load if the autoFocus prop/attribute is used.
The problem stems from the following switch cases where only the button, input, select and textarea inputs are supported:
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!