Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit 017f016

Browse files
committed
Merge branch 'tabindex'
2 parents bb6b5c1 + 166709c commit 017f016

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const CLOSE_ATTR = 'data-close-dialog'
44
const CLOSE_SELECTOR = `[${CLOSE_ATTR}]`
5-
const INPUT_SELECTOR = 'a, input, button, textarea, select, summary'
65

76
type Focusable =
87
| HTMLButtonElement
@@ -33,7 +32,7 @@ function keydown(event: KeyboardEvent): void {
3332
}
3433

3534
function focusable(el: Focusable): boolean {
36-
return !el.disabled && !el.hidden && (!el.type || el.type !== 'hidden') && !el.closest('[hidden]')
35+
return el.tabIndex >= 0 && !el.disabled && !el.hidden && (!el.type || el.type !== 'hidden') && !el.closest('[hidden]')
3736
}
3837

3938
function restrictTabBehavior(event: KeyboardEvent): void {
@@ -42,7 +41,7 @@ function restrictTabBehavior(event: KeyboardEvent): void {
4241
if (!dialog) return
4342
event.preventDefault()
4443

45-
const elements: Array<Focusable> = Array.from(dialog.querySelectorAll(INPUT_SELECTOR)).filter(focusable)
44+
const elements: Array<Focusable> = Array.from(dialog.querySelectorAll('*')).filter(focusable)
4645
if (elements.length === 0) return
4746

4847
const movement = event.shiftKey ? -1 : 1
@@ -158,9 +157,6 @@ class DetailsDialogElement extends HTMLElement {
158157
static get CLOSE_SELECTOR() {
159158
return CLOSE_SELECTOR
160159
}
161-
static get INPUT_SELECTOR() {
162-
return INPUT_SELECTOR
163-
}
164160

165161
constructor() {
166162
super()

0 commit comments

Comments
 (0)