Skip to content

Commit

Permalink
Fix wrong item being selected when navigating search items
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-va committed Dec 9, 2024
1 parent 8ac0f79 commit 0ac6c37
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions ui/src/components/search/search-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ export class SearchInput extends LitElementI18n {
}

private selectItem(item: SearchItem, options: { keepFocus?: boolean } = {}): void {
console.log('select', item);
const categorized = categorizeSearchItem(item);
switch (categorized.category) {
case SearchItemCategory.Location:
Expand Down Expand Up @@ -243,10 +242,12 @@ export class SearchInput extends LitElementI18n {
// rectangle is too small
const center = Rectangle.center(rectangle);
center.height = 5000;
this.viewer.camera.cancelFlight();
this.viewer.camera.flyTo({
destination: Cartographic.toCartesian(center),
});
} else {
this.viewer.camera.cancelFlight();
this.viewer.camera.flyTo({
destination: rectangle,
});
Expand Down Expand Up @@ -290,11 +291,15 @@ export class SearchInput extends LitElementI18n {
}
case 'ArrowUp':
case 'ArrowDown': {
const target = this.findActiveResult();
if (target != null) {
const [item, _element] = target;
this.selectItem(item, {keepFocus: true});
}
// Wait for a short interval before attempting to detect the currently selected item
// so the search has time to update the DOM.
setTimeout(() => {
const target = this.findActiveResult();
if (target != null) {
const [item, _element] = target;
this.selectItem(item, {keepFocus: true});
}
});
break;
}
default:
Expand Down Expand Up @@ -333,6 +338,7 @@ export class SearchInput extends LitElementI18n {
const child = results.children[i];
if (child.ariaSelected === 'true') {
const item = this.resultItems[i];
console.log(item, child);
return [item, child as HTMLLIElement];
}
}
Expand Down

0 comments on commit 0ac6c37

Please sign in to comment.