Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Auto-scroll the search result list to keep the selection in view #35

Merged
merged 1 commit into from
Jun 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Searchbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ export default {
return highlightedValue;
},
},
methods: {
down() {
if (this.current < this.items.length - 1) {
this.current += 1;
this.scrollListView();
}
},
up() {
if (this.current > 0) {
this.current -= 1;
this.scrollListView();
}
},
scrollListView() {
const { dropdown } = this.$els;
const currentEntry = dropdown.children[this.current];
const upperBound = dropdown.scrollTop;
const lowerBound = upperBound + dropdown.clientHeight;
const currentEntryOffsetBottom = currentEntry.offsetTop + currentEntry.offsetHeight;
if (currentEntry.offsetTop < upperBound) {
dropdown.scrollTop = currentEntry.offsetTop;
} else if (currentEntryOffsetBottom > lowerBound) {
dropdown.scrollTop = currentEntryOffsetBottom - dropdown.clientHeight;
}
},
},
};
</script>

Expand Down