Skip to content

Commit

Permalink
fix: scrolling when using keyboard navigation
Browse files Browse the repository at this point in the history
feed-item-row height is actual 110.66px, but setting this fixed is not optimal and should be changed in the future.

Signed-off-by: Wolfgang <github@linux-dude.de>
  • Loading branch information
wofferl authored and Grotax committed Sep 29, 2024
1 parent 008c189 commit fb97832
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/components/feed-display/FeedItemDisplayList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default Vue.extend({
return response.sort(this.sort)
},
// Trigger the click event programmatically to benefit from the item handling inside the FeedItemRow component
clickItem(item: FeedItem, alignToTop = false) {
clickItem(item: FeedItem) {
if (!item) {
return
}
Expand All @@ -249,8 +249,8 @@ export default Vue.extend({
if (element) {
element.click()
const virtualScroll = this.$refs.virtualScroll
// TODO: This is still jerky and even can derail the current item
// virtualScroll.showElement(element, alignToTop)
virtualScroll.showElement(element)
}
},
currentIndex(items: FeedItem[]): number {
Expand All @@ -266,7 +266,7 @@ export default Vue.extend({
// Jump to the previous item
if (currentIndex > 0) {
const previousItem = items[currentIndex - 1]
this.clickItem(previousItem, true)
this.clickItem(previousItem)
}
},
jumpToNextItem() {
Expand All @@ -275,7 +275,7 @@ export default Vue.extend({
// Jump to the first item, if none was selected, otherwise jump to the next item
if (currentIndex === -1 || (currentIndex < items.length - 1)) {
const nextItem = items[currentIndex + 1]
this.clickItem(nextItem, false)
this.clickItem(nextItem)
}
},
},
Expand Down
9 changes: 2 additions & 7 deletions src/components/feed-display/VirtualScroll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ItemSkeleton from './ItemSkeleton.vue'
const GRID_ITEM_HEIGHT = 200 + 10
// const GRID_ITEM_WIDTH = 250 + 10
const LIST_ITEM_HEIGHT = 45 + 1
const LIST_ITEM_HEIGHT = 110 + 1
export default Vue.extend({
name: 'VirtualScroll',
Expand Down Expand Up @@ -47,9 +47,6 @@ export default Vue.extend({
this.$el.scrollTop = 0
},
},
created() {
this.elementToShowAlignToTop = false
},
mounted() {
this.onScroll()
window.addEventListener('resize', this.onScroll)
Expand All @@ -64,7 +61,6 @@ export default Vue.extend({
},
showElement(element, alignToTop) {

Check warning on line 62 in src/components/feed-display/VirtualScroll.vue

View workflow job for this annotation

GitHub Actions / eslint node

'alignToTop' is defined but never used
this.elementToShow = element
this.elementToShowAlignToTop = alignToTop
},
},
render(h) {
Expand Down Expand Up @@ -115,8 +111,7 @@ export default Vue.extend({
const scrollTop = this.scrollTop
this.$nextTick(() => {
if (this.elementToShow) {
// this.elementToShow.scrollIntoView(this.elementToShowAlignToTop)
this.elementToShow.scrollIntoView({ behavior: 'smooth', block: 'center' })
this.elementToShow.scrollIntoView({ behavior: 'auto', block: 'nearest' })
this.elementToShow = null
} else {
this.$el.scrollTop = scrollTop
Expand Down

0 comments on commit fb97832

Please sign in to comment.