This repository was archived by the owner on Sep 22, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed
Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ type Focusable =
1212 | HTMLElement
1313
1414function autofocus ( el : DetailsDialogElement ) : void {
15- let autofocusElement = el . querySelector ( '[autofocus]' )
15+ let autofocusElement = Array . from ( el . querySelectorAll ( '[autofocus]' ) ) . filter ( focusable ) [ 0 ]
1616 if ( ! autofocusElement ) {
1717 autofocusElement = el
1818 el . setAttribute ( 'tabindex' , '-1' )
@@ -32,7 +32,11 @@ function keydown(event: KeyboardEvent): void {
3232}
3333
3434function focusable ( el : Focusable ) : boolean {
35- return el . tabIndex >= 0 && ! el . disabled && ! el . hidden && ( ! el . type || el . type !== 'hidden' ) && ! el . closest ( '[hidden]' )
35+ return el . tabIndex >= 0 && ! el . disabled && visible ( el )
36+ }
37+
38+ function visible ( el ) : boolean {
39+ return ! el . hidden && ( ! el . type || el . type !== 'hidden' ) && ( el . offsetWidth > 0 || el . offsetHeight > 0 )
3640}
3741
3842function restrictTabBehavior ( event : KeyboardEvent ) : void {
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ describe('details-dialog-element', function() {
2929 <button data-button>Button</button>
3030 <button hidden>hidden</button>
3131 <div hidden><button>hidden</button></div>
32+ <details><button>Button in closed details</button></details>
3233 <button ${ CLOSE_ATTR } >Goodbye</button>
3334 </details-dialog>
3435 </details>
You can’t perform that action at this time.
0 commit comments