From e493439324278e3a15ba51cfb9c45ec226328257 Mon Sep 17 00:00:00 2001 From: Kael Date: Tue, 21 Feb 2023 23:53:10 +1100 Subject: [PATCH] fix(VVirtualScroll): clamp visible items to [0, items.length] see #16725 --- packages/vuetify/src/labs/VVirtualScroll/VVirtualScroll.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/vuetify/src/labs/VVirtualScroll/VVirtualScroll.tsx b/packages/vuetify/src/labs/VVirtualScroll/VVirtualScroll.tsx index b0436a59272..fc46c482ebd 100644 --- a/packages/vuetify/src/labs/VVirtualScroll/VVirtualScroll.tsx +++ b/packages/vuetify/src/labs/VVirtualScroll/VVirtualScroll.tsx @@ -12,6 +12,7 @@ import { useResizeObserver } from '@/composables/resizeObserver' // Utilities import { computed, onMounted, ref, watchEffect } from 'vue' import { + clamp, convertToUnit, createRange, genericComponent, @@ -114,9 +115,9 @@ export const VVirtualScroll = genericComponent() => { 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