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

Commit 66c9d4a

Browse files
committed
Fix shift tabbing without current focus
1 parent 63eb86a commit 66c9d4a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@ function restrictTabBehavior(event: KeyboardEvent): void {
5050

5151
const movement = event.shiftKey ? -1 : 1
5252
const currentFocus = dialog.contains(document.activeElement) ? document.activeElement : null
53-
let targetIndex = 0
53+
let targetIndex = movement === -1 ? -1 : 0
5454

5555
if (currentFocus) {
5656
const currentIndex = elements.indexOf(currentFocus)
5757
if (currentIndex !== -1) {
58-
const newIndex = currentIndex + movement
59-
if (newIndex < 0) {
60-
targetIndex = elements.length - 1
61-
} else {
62-
targetIndex = newIndex % elements.length
63-
}
58+
targetIndex = currentIndex + movement
6459
}
6560
}
6661

62+
if (targetIndex < 0) {
63+
targetIndex = elements.length - 1
64+
} else {
65+
targetIndex = targetIndex % elements.length
66+
}
67+
6768
elements[targetIndex].focus()
6869
}
6970

0 commit comments

Comments
 (0)