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 =
12
12
| HTMLElement
13
13
14
14
function autofocus ( el : DetailsDialogElement ) : void {
15
- let autofocusElement = el . querySelector ( '[autofocus]' )
15
+ let autofocusElement = Array . from ( el . querySelectorAll ( '[autofocus]' ) ) . filter ( focusable ) [ 0 ]
16
16
if ( ! autofocusElement ) {
17
17
autofocusElement = el
18
18
el . setAttribute ( 'tabindex' , '-1' )
@@ -32,7 +32,11 @@ function keydown(event: KeyboardEvent): void {
32
32
}
33
33
34
34
function 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 )
36
40
}
37
41
38
42
function restrictTabBehavior ( event : KeyboardEvent ) : void {
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ describe('details-dialog-element', function() {
29
29
<button data-button>Button</button>
30
30
<button hidden>hidden</button>
31
31
<div hidden><button>hidden</button></div>
32
+ <details><button>Button in closed details</button></details>
32
33
<button ${ CLOSE_ATTR } >Goodbye</button>
33
34
</details-dialog>
34
35
</details>
You can’t perform that action at this time.
0 commit comments