Skip to content

Commit

Permalink
fix(VVirtualScroll): clamp visible items to [0, items.length]
Browse files Browse the repository at this point in the history
see #16725
  • Loading branch information
KaelWD committed Feb 21, 2023
1 parent f07101c commit e493439
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/vuetify/src/labs/VVirtualScroll/VVirtualScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useResizeObserver } from '@/composables/resizeObserver'
// Utilities
import { computed, onMounted, ref, watchEffect } from 'vue'
import {
clamp,
convertToUnit,
createRange,
genericComponent,
Expand Down Expand Up @@ -114,9 +115,9 @@ export const VVirtualScroll = genericComponent<new <T>() => {
const midPointIndex = calculateMidPointIndex(scrollTop + height / 2)
const buffer = Math.round(visibleItems.value / 3)
if (direction === UP && midPointIndex <= first.value + (buffer * 2) - 1) {
first.value = Math.max(midPointIndex - buffer, 0)
first.value = clamp(midPointIndex - buffer, 0, props.items.length)
} else if (direction === DOWN && midPointIndex >= first.value + (buffer * 2) - 1) {
first.value = Math.min(Math.max(0, midPointIndex - buffer), props.items.length - visibleItems.value)
first.value = clamp(midPointIndex - buffer, 0, props.items.length - visibleItems.value)
}

lastScrollTop = rootEl.value.scrollTop
Expand Down

0 comments on commit e493439

Please sign in to comment.