Skip to content

Commit

Permalink
Cleans up scrollTo's element finding
Browse files Browse the repository at this point in the history
This commit replaces a somewhat convoluted query chain with
a single querySelector to fetch the specific element we want to
focus on.

This feels slightly cleaner to my eyes, but has the added benefit
of ensuring it works correctly with something like "vertical-collection",
which occluding certain elements from the list for performance reasons.
This was causing keyboard-navigation to fail unexpectedly, since `.item(19)`
was no longer guaranteed to be the item with `data-option-index='19'`, or
even to exist.
  • Loading branch information
matthew-robertson committed Feb 9, 2022
1 parent c2f917e commit 4b60a16
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion addon/components/power-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export default class PowerSelect extends Component<PowerSelectArgs> {
if (index === -1) {
return;
}
let optionElement = (optionsList.querySelectorAll('[data-option-index]') as NodeListOf<HTMLElement>).item(index);
let optionElement = optionsList.querySelector(`[data-option-index='${index}']`) as HTMLElement;
if (!optionElement) {
return;
}
Expand Down

0 comments on commit 4b60a16

Please sign in to comment.