Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,11 @@ export const VAutocomplete = genericComponent<new <
const index = displayItems.value.findIndex(
item => model.value.some(s => item.value === s.value)
)
IN_BROWSER && window.requestAnimationFrame(() => {
index >= 0 && vVirtualScrollRef.value?.scrollToIndex(index)
})
if (index >= 0 && IN_BROWSER) {
window.requestAnimationFrame(() => {
vVirtualScrollRef.value?.scrollToIndex(index)
})
}
}
if (val) _searchLock.value = null
})
Expand Down
20 changes: 12 additions & 8 deletions packages/vuetify/src/composables/virtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ export function useVirtual <T> (props: VirtualProps, items: Ref<readonly T[]>) {

const unwatch = watch(hasInitialRender, v => {
if (!v) return
// First render is complete, update offsets and visible
// items in case our assumed item height was incorrect

unwatch()
markerOffset = markerRef.value!.offsetTop
Expand All @@ -122,7 +120,7 @@ export function useVirtual <T> (props: VirtualProps, items: Ref<readonly T[]>) {
const prevHeight = sizes[index]
const prevMinHeight = itemHeight.value

itemHeight.value = prevMinHeight ? Math.min(itemHeight.value, height) : height
itemHeight.value = prevMinHeight ? itemHeight.value : height

if (prevHeight !== height || prevMinHeight !== itemHeight.value) {
sizes[index] = height
Expand Down Expand Up @@ -167,10 +165,9 @@ export function useVirtual <T> (props: VirtualProps, items: Ref<readonly T[]>) {
const scrollDeltaT = scrollTime - lastScrollTime

if (scrollDeltaT > 500) {
scrollVelocity = Math.sign(scrollTop - lastScrollTop)

// Not super important, only update at the
// start of a scroll sequence to avoid reflows
// FIX: use 0 instead of Math.sign to ensure both first and last
// are updated correctly after a long pause (e.g. after programmatic scroll)
scrollVelocity = 0
markerOffset = markerRef.value.offsetTop
} else {
scrollVelocity = scrollTop - lastScrollTop
Expand All @@ -184,6 +181,7 @@ export function useVirtual <T> (props: VirtualProps, items: Ref<readonly T[]>) {

calculateVisibleItems()
}

function handleScrollend () {
if (!containerRef.value || !markerRef.value) return

Expand Down Expand Up @@ -224,7 +222,6 @@ export function useVirtual <T> (props: VirtualProps, items: Ref<readonly T[]>) {
first.value = start
last.value = end
} else {
// Only update the side that's reached its limit if there's still buffer left
if (start <= 0) first.value = start
if (end >= items.value.length) last.value = end
}
Expand All @@ -236,10 +233,17 @@ export function useVirtual <T> (props: VirtualProps, items: Ref<readonly T[]>) {

function scrollToIndex (index: number) {
const offset = calculateOffset(index)

if (!containerRef.value || (index && !offset)) {
targetScrollIndex = index
} else {
containerRef.value.scrollTop = offset
lastScrollTop = offset
scrollVelocity = 0
lastScrollTime = performance.now()
targetScrollIndex = -1
cancelAnimationFrame(raf)
_calculateVisibleItems()
}
}

Expand Down
Loading