Bug 213982

Summary: WebKit autofocuses the last available autofocus element instead of the first available
Product: WebKit Reporter: Maciej Stachowiak <mjs>
Component: FormsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: cdumez, rniwa, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   

Description Maciej Stachowiak 2020-07-05 20:29:09 PDT
WebKit autofocuses the last available autofocus element instead of the first available. Other browsers autofocus the first. 

Here is a test case: https://mehdi.cc/tests/multiple-autofocus/

In Safari, this focuses Field 2. In Firefox and Chrome, Field 1.

The spec says to autofocus the first. Well, sort of... autofocus for purposes of page load focus is only considered at element insertion time, not when the attribute is added or removed; and it's not the first element in document order that wins, it's the first (eligible) to be inserted.


Full spec details are here: https://html.spec.whatwg.org/#the-autofocus-attribute
Comment 1 Radar WebKit Bug Importer 2020-07-05 20:29:28 PDT
<rdar://problem/65116588>
Comment 2 Ryosuke Niwa 2020-09-26 15:25:25 PDT

*** This bug has been marked as a duplicate of bug 203139 ***