Content-Length: 334856 | pFad | http://github.com/vueuse/vueuse/commit/d23812dbebece77e5e0bd6d9d3574a3637ac31b0

88 fix(useVirtualList): resolve invalid watch source (#4857) · vueuse/vueuse@d23812d · GitHub
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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/vueuse/vueuse/commit/d23812dbebece77e5e0bd6d9d3574a3637ac31b0

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy