Bug 261621 - formAssociated=true causes custom element to become focusable
Summary: formAssociated=true causes custom element to become focusable
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: sideshowbarker
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks: 154907
  Show dependency treegraph
 
Reported: 2023-09-15 14:23 PDT by James Tu
Modified: 2023-10-02 16:20 PDT (History)
7 users (show)

See Also:


Attachments
Repro (364 bytes, text/html)
2023-09-15 14:23 PDT, James Tu
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.