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

Commit

Permalink
Merge pull request #35 from nusjzx/258-search-dropdown-autoscroll
Browse files Browse the repository at this point in the history
Auto-scroll the search result list to keep the selection in view
  • Loading branch information
yamgent committed Jun 11, 2018
2 parents 9d4ec8d + 48f8c18 commit d41bc2d
Showing 1 changed file with 26 additions and 0 deletions.
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

0 comments on commit d41bc2d

Please sign in to comment.