RESOLVED INVALID 260480
Custom element with delegatesFocus does not focus if inner element is not first child
https://bugs.webkit.org/show_bug.cgi?id=260480
Summary Custom element with delegatesFocus does not focus if inner element is not fir...
Elizabeth Mitchell
Reported 2023-08-21 12:46:24 PDT
A custom element with `delegatesFocus: true` does not correctly delegate focus if the first child of the custom element's shadow DOM is not focusable. This is common with wrapper divs and styling. ``` <!-- Does not delegate focus correctly --> <x-button> #shadow-root <div class="style"> <button><slot></slot></button> </div> </x-button> <!-- Delegates focus correctly --> <x-button> #shadow-root <button><slot></slot></button> </x-button> ``` See https://jsbin.com/ranuvuhiri/edit?html,output and click on "Focus button" Expected: custom element button is focused Actual: button is not focused Tested in Safari 16.6 on MacOS 13.5
Attachments
Reduction (667 bytes, text/html)
2024-03-28 15:15 PDT, Ryosuke Niwa
no flags
Radar WebKit Bug Importer
Comment 1 2023-08-28 12:47:14 PDT
Ryosuke Niwa
Comment 2 2024-03-28 15:10:54 PDT
Hm... the focus is set. We're somehow not applying :focus rule, however.
Ryosuke Niwa
Comment 3 2024-03-28 15:15:25 PDT
Created attachment 470649 [details] Reduction
Ryosuke Niwa
Comment 4 2024-03-28 15:27:55 PDT
Oh, the issue is simply that x-button becomes width 0px because it'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.
Note You need to log in before you can comment on or make changes to this bug.