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

Commit 6e51fb9

Browse files
committed
Update query for focusable elements
1 parent 9da29cd commit 6e51fb9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

index.js

Lines changed: 5 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,10 @@ 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 (
36+
(el.hasAttribute('tabindex') || el.tabIndex >= 0) &&
37+
(!el.disabled && !el.hidden && (!el.type || el.type !== 'hidden') && !el.closest('[hidden]'))
38+
)
3739
}
3840

3941
function restrictTabBehavior(event: KeyboardEvent): void {
@@ -42,7 +44,7 @@ function restrictTabBehavior(event: KeyboardEvent): void {
4244
if (!dialog) return
4345
event.preventDefault()
4446

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

4850
const movement = event.shiftKey ? -1 : 1
@@ -141,9 +143,6 @@ class DetailsDialogElement extends HTMLElement {
141143
static get CLOSE_SELECTOR() {
142144
return CLOSE_SELECTOR
143145
}
144-
static get INPUT_SELECTOR() {
145-
return INPUT_SELECTOR
146-
}
147146

148147
constructor() {
149148
super()

0 commit comments

Comments
 (0)