<?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>260480</bug_id>
          
          <creation_ts>2023-08-21 12:46:24 -0700</creation_ts>
          <short_desc>Custom element with delegatesFocus does not focus if inner element is not first child</short_desc>
          <delta_ts>2024-03-28 15:28:13 -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 16</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 13</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc>https://jsbin.com/ranuvuhiri/edit?html,output</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>148695</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Elizabeth Mitchell">lizmitchell</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>mike</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1972458</commentid>
    <comment_count>0</comment_count>
    <who name="Elizabeth Mitchell">lizmitchell</who>
    <bug_when>2023-08-21 12:46:24 -0700</bug_when>
    <thetext>A custom element with `delegatesFocus: true` does not correctly delegate focus if the first child of the custom element&apos;s shadow DOM is not focusable.

This is common with wrapper divs and styling.

```
&lt;!-- Does not delegate focus correctly --&gt;
&lt;x-button&gt;
  #shadow-root
    &lt;div class=&quot;style&quot;&gt;
      &lt;button&gt;&lt;slot&gt;&lt;/slot&gt;&lt;/button&gt;
    &lt;/div&gt;
&lt;/x-button&gt;

&lt;!-- Delegates focus correctly --&gt;
&lt;x-button&gt;
  #shadow-root
    &lt;button&gt;&lt;slot&gt;&lt;/slot&gt;&lt;/button&gt;
&lt;/x-button&gt;
```

See https://jsbin.com/ranuvuhiri/edit?html,output and click on &quot;Focus button&quot;

Expected: custom element button is focused
Actual: button is not focused

Tested in Safari 16.6 on MacOS 13.5</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1974002</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-08-28 12:47:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/114580905&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2024568</commentid>
    <comment_count>2</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2024-03-28 15:10:54 -0700</bug_when>
    <thetext>Hm... the focus is set. We&apos;re somehow not applying :focus rule, however.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2024571</commentid>
    <comment_count>3</comment_count>
      <attachid>470649</attachid>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2024-03-28 15:15:25 -0700</bug_when>
    <thetext>Created attachment 470649
Reduction</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2024575</commentid>
    <comment_count>4</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2024-03-28 15:27:55 -0700</bug_when>
    <thetext>Oh, the issue is simply that x-button becomes width 0px because it&apos;s a display: inline. If you set display: block on x-button or replace div with span, the dotted red line renders correctly.

Note that buttons are not focusable by mouse clicks on Apple platforms by default. If you want to make a button focusable, set tabindex=0 on button elements.

As such, this is behaving correctly.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>470649</attachid>
            <date>2024-03-28 15:15:25 -0700</date>
            <delta_ts>2024-03-28 15:15:25 -0700</delta_ts>
            <desc>Reduction</desc>
            <filename>delegates-focus.html</filename>
            <type>text/html</type>
            <size>667</size>
            <attacher name="Ryosuke Niwa">rniwa</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxzdHlsZT4KICA6Zm9jdXMgewogICAgYmFja2dyb3VuZDogZ3JlZW47
CiAgfQo8L3N0eWxlPgo8YnI+Cjx4LWJ1dHRvbiBpZD0iYnV0dG9uMSI+CiAgPHRlbXBsYXRlIHNo
YWRvd3Jvb3Rtb2RlPSJvcGVuIiBzaGFkb3dyb290ZGVsZWdhdGVzZm9jdXM9InRydWUiPgogICAg
PGRpdj48aW5wdXQ+PHNwYW4gb25jbGljaz0ic2V0VGltZW91dCgoKSA9PiBidXR0b24xLnNoYWRv
d1Jvb3QucXVlcnlTZWxlY3Rvcignc3BhbicpLnRleHRDb250ZW50ID0gZG9jdW1lbnQuYWN0aXZl
RWxlbWVudCA9PSBidXR0b24xID8gJ1BBU1MnIDogJ0ZBSUwnLCAwKSI+Y2xpY2sgaGVyZTwvc3Bh
bj48L2Rpdj4KICA8L3RlbXBsYXRlPgo8L3gtYnV0dG9uPgo8eC1idXR0b24gaWQ9ImJ1dHRvbjIi
PgogIDx0ZW1wbGF0ZSBzaGFkb3dyb290bW9kZT0ib3BlbiIgc2hhZG93cm9vdGRlbGVnYXRlc2Zv
Y3VzPSJ0cnVlIj4KICAgIDxpbnB1dD48c3BhbiBvbmNsaWNrPSJzZXRUaW1lb3V0KCgpID0+IGJ1
dHRvbjIuc2hhZG93Um9vdC5xdWVyeVNlbGVjdG9yKCdzcGFuJykudGV4dENvbnRlbnQgPSBkb2N1
bWVudC5hY3RpdmVFbGVtZW50ID09IGJ1dHRvbjIgPyAnUEFTUycgOiAnRkFJTCcsIDApIj5jbGlj
ayBoZXJlPC9zcGFuPgogIDwvdGVtcGxhdGU+CjwveC1idXR0b24+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>