Bug 261621

Summary: formAssociated=true causes custom element to become focusable
Product: WebKit Reporter: James Tu <j.tu>
Component: DOMAssignee: sideshowbarker <mike>
Status: RESOLVED FIXED    
Severity: Normal CC: akeerthi, karlcow, mike, nlawson, ntim, rniwa, webkit-bug-importer
Priority: P2 Keywords: BrowserCompat, InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://github.com/web-platform-tests/wpt/pull/42287
Bug Depends on:    
Bug Blocks: 154907    
Attachments:
Description Flags
Repro none

Description James Tu 2023-09-15 14:23:56 PDT
Created attachment 467691 [details]
Repro

When enabling formAssociated on a custom element, it becomes focusable whereas when formAssociated is false it is not.

Chrome and Firefox both do not exhibit this behavior but it does occur in Safari Technology Preview Release 178 (Safari 17.0, WebKit 18617.1.6).

When setting formAssociated=false Safari behaves the same as Chrome and Firefox.

Attached is a repro showing that calling element.focus() with formAssociated=true causes focus to move to the element, which is demonstrated by document.activeElement below.


customElements.define(
    'x-foo',
    class Foo extends HTMLElement {
        static formAssociated = true;
    }
);
const foo = document.querySelector('x-foo');
foo.focus();
console.log(document.activeElement);

Note document.activeElement is <body> in Chrome and Firefox but <x-foo> in Safari.

Note that the spec does not imply any kind of focus behavior for formAssociated:
https://html.spec.whatwg.org/multipage/custom-elements.html#form-associated-custom-elements
Comment 1 Radar WebKit Bug Importer 2023-09-22 14:24:23 PDT
<rdar://problem/115909679>
Comment 2 sideshowbarker 2023-10-02 00:19:50 PDT
Pull request: https://github.com/WebKit/WebKit/pull/18487
Comment 3 sideshowbarker 2023-10-02 10:02:16 PDT
Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/42287
Comment 4 EWS 2023-10-02 16:20:53 PDT
Committed 268756@main (7e0cd07bab81): <https://commits.webkit.org/268756@main>

Reviewed commits have been landed. Closing PR #18487 and removing active labels.