Skip to content

Commit d23812d

Browse files
cszhjhOrbisKautofix-ci[bot]
authored
fix(useVirtualList): resolve invalid watch source (#4857)
Co-authored-by: Robin <robin.kehl@singular-it.de> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent bb83178 commit d23812d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/core/useVirtualList/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ describe('useVirtualList', () => {
66
it('should be defined', () => {
77
expect(useVirtualList).toBeDefined()
88
})
9+
10+
it('should accept plain arrays as input', () => {
11+
const {
12+
list,
13+
containerProps: { ref: containerRef },
14+
scrollTo,
15+
} = useVirtualList(['a', 'b', 'c', 'd', 'e', 'f'], { itemHeight: () => 50 })
16+
const div = { ...document.createElement('div'), clientHeight: 100 }
17+
18+
containerRef.value = div
19+
scrollTo(0)
20+
expect(list.value.map(i => i.data)).toEqual(['a', 'b', 'c', 'd', 'e', 'f'])
21+
})
922
})
1023

1124
describe('useVirtualList, vertical', () => {

packages/core/useVirtualList/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ComputedRef, MaybeRef, Ref, ShallowRef, StyleValue } from 'vue'
2-
import { computed, ref as deepRef, shallowRef, watch } from 'vue'
2+
import { computed, ref as deepRef, shallowRef, toValue, watch } from 'vue'
33
import { useElementSize } from '../useElementSize'
44

55
type UseVirtualListItemSize = number | ((index: number) => number)
@@ -201,7 +201,7 @@ function createGetDistance<T>(itemSize: UseVirtualListItemSize, source: UseVirtu
201201
}
202202

203203
function useWatchForSizes<T>(size: UseVirtualElementSizes, list: MaybeRef<readonly T[]>, containerRef: Ref<HTMLElement | null>, calculateRange: () => void) {
204-
watch([size.width, size.height, list, containerRef], () => {
204+
watch([size.width, size.height, () => toValue(list), containerRef], () => {
205205
calculateRange()
206206
})
207207
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy