<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>261621</bug_id>
          
          <creation_ts>2023-09-15 14:23:56 -0700</creation_ts>
          <short_desc>formAssociated=true causes custom element to become focusable</short_desc>
          <delta_ts>2023-10-02 16:20:56 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://github.com/web-platform-tests/wpt/pull/42287</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>154907</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="James Tu">j.tu</reporter>
          <assigned_to name="sideshowbarker">mike</assigned_to>
          <cc>akeerthi</cc>
    
    <cc>karlcow</cc>
    
    <cc>mike</cc>
    
    <cc>nlawson</cc>
    
    <cc>ntim</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1977762</commentid>
    <comment_count>0</comment_count>
      <attachid>467691</attachid>
    <who name="James Tu">j.tu</who>
    <bug_when>2023-09-15 14:23:56 -0700</bug_when>
    <thetext>Created attachment 467691
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(
    &apos;x-foo&apos;,
    class Foo extends HTMLElement {
        static formAssociated = true;
    }
);
const foo = document.querySelector(&apos;x-foo&apos;);
foo.focus();
console.log(document.activeElement);

Note document.activeElement is &lt;body&gt; in Chrome and Firefox but &lt;x-foo&gt; 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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979453</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-09-22 14:24:23 -0700</bug_when>
    <thetext>&lt;rdar://problem/115909679&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1981702</commentid>
    <comment_count>2</comment_count>
    <who name="sideshowbarker">mike</who>
    <bug_when>2023-10-02 00:19:50 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/18487</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1981780</commentid>
    <comment_count>3</comment_count>
    <who name="sideshowbarker">mike</who>
    <bug_when>2023-10-02 10:02:16 -0700</bug_when>
    <thetext>Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/42287</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1981902</commentid>
    <comment_count>4</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-10-02 16:20:53 -0700</bug_when>
    <thetext>Committed 268756@main (7e0cd07bab81): &lt;https://commits.webkit.org/268756@main&gt;

Reviewed commits have been landed. Closing PR #18487 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>467691</attachid>
            <date>2023-09-15 14:23:56 -0700</date>
            <delta_ts>2023-09-15 14:23:56 -0700</delta_ts>
            <desc>Repro</desc>
            <filename>repro.html</filename>
            <type>text/html</type>
            <size>364</size>
            <attacher name="James Tu">j.tu</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgogICAgPHgtZm9vPjwveC1mb28+CiAgICA8c2NyaXB0Pgog
ICAgICAgIGN1c3RvbUVsZW1lbnRzLmRlZmluZSgKICAgICAgICAgICAgJ3gtZm9vJywKICAgICAg
ICAgICAgY2xhc3MgRm9vIGV4dGVuZHMgSFRNTEVsZW1lbnQgewogICAgICAgICAgICAgICAgc3Rh
dGljIGZvcm1Bc3NvY2lhdGVkID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgICk7CiAgICAg
ICAgY29uc3QgZm9vID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvcigneC1mb28nKTsKICAgICAgICBm
b28uZm9jdXMoKTsKICAgICAgICBjb25zb2xlLmxvZyhkb2N1bWVudC5hY3RpdmVFbGVtZW50KTsK
ICAgIDwvc2NyaXB0Pgo8L2h0bWw+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>