Skip to content

Commit 9b432d1

Browse files
committed
a11y: focus the element when navigating with keyboard or screen reader
1 parent bd2b15a commit 9b432d1

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

paginator.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,17 +1017,20 @@ export class Paginator extends HTMLElement {
10171017
.find(r => r.width > 0 && r.height > 0) || rects[0]
10181018
if (!rect) return
10191019
await this.#scrollToRect(rect, reason)
1020-
let node = anchor.focus ? anchor : undefined
1021-
if (!node && anchor.startContainer) {
1022-
node = anchor.startContainer
1023-
if (node.nodeType === Node.TEXT_NODE) {
1024-
node = node.parentElement
1020+
// focus the element when navigating with keyboard or screen reader
1021+
if (reason === 'navigation') {
1022+
let node = anchor.focus ? anchor : undefined
1023+
if (!node && anchor.startContainer) {
1024+
node = anchor.startContainer
1025+
if (node.nodeType === Node.TEXT_NODE) {
1026+
node = node.parentElement
1027+
}
1028+
}
1029+
if (node && node.focus) {
1030+
node.tabIndex = -1
1031+
node.style.outline = 'none'
1032+
node.focus({ preventScroll: true })
10251033
}
1026-
}
1027-
if (node && node.focus) {
1028-
node.tabIndex = -1
1029-
node.style.outline = 'none'
1030-
node.focus({ preventScroll: true })
10311034
}
10321035
return
10331036
}

0 commit comments

Comments
 (0)