react / react/react

autoFocus polyfill deviates from HTML autofocus global attribute spec

Open
#23,231 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Needs Investigation
Dominant language
JavaScript
Stars
251k
Forks
51.4k
Avg merge
2d 4h
Merged PRs (30d)
53

Description

Based on this comment: https://github.com/facebook/react/issues/11851#issuecomment-351672131, it appears autoFocus is meant to bring a consistent behavior to match HTML's autofocus.

https://html.spec.whatwg.org/multipage/interaction.html#the-autofocus-attribute

The above spec outlines that the first element with autofocus found in the DOM should be the one focused, and the others discarded ("flush autofocus candidates" steps 5.11.1 through 5.11.3).

However, the behavior of React's autoFocus polyfill is to set focus to the last element in the DOM with the attribute.

Ideally React's implementation should match the spec, behavior-wise.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the autoFocus polyfill implementation and compare its behavior with the linked HTML autofocus specification. Reproduce a case with multiple autofocus elements and verify that the first element in DOM order receives focus; done means the implementation matches that behavior and the relevant regression coverage passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.