Skip to content

Commit ec33549

Browse files
committed
Use visible check instead of hidden for futureproofing
1 parent 4a79ecc commit ec33549

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/combobox-nav.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,17 @@ function fireCommitEvent(target: Element): void {
8585
)
8686
}
8787

88+
function visible(el): boolean {
89+
return !el.hidden && (!el.type || el.type !== 'hidden') && (el.offsetWidth > 0 || el.offsetHeight > 0)
90+
}
91+
8892
export function navigate(
8993
input: HTMLTextAreaElement | HTMLInputElement,
9094
list: HTMLElement,
9195
indexDiff: -1 | 1 = 1
9296
): void {
93-
const focusEl = list.querySelector('[aria-selected="true"]:not([hidden])')
94-
const els = Array.from(list.querySelectorAll('[role="option"]:not([hidden])'))
97+
const focusEl = Array.from(list.querySelectorAll('[aria-selected="true"]')).filter(visible)[0]
98+
const els = Array.from(list.querySelectorAll('[role="option"]')).filter(visible)
9599
const focusIndex = els.indexOf(focusEl)
96100
let indexOfItem = indexDiff === 1 ? 0 : els.length - 1
97101
if (focusEl && focusIndex >= 0) {

0 commit comments

Comments
 (0)