Skip to content

Commit 9cb81d5

Browse files
feat(Listbox/Tree): handle estimateSize as function for Virtualizer (#2288)
1 parent b1e4ad3 commit 9cb81d5

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/core/src/Listbox/ListboxVirtualizer.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface ListboxVirtualizerProps<T extends AcceptableValue = AcceptableV
55
/** Number of items rendered outside the visible area */
66
overscan?: number
77
/** Estimated size (in px) of each item */
8-
estimateSize?: number
8+
estimateSize?: number | ((index: number) => number)
99
/** Text content for each item to achieve type-ahead feature */
1010
textContent?: (option: T) => string
1111
}
@@ -64,7 +64,10 @@ const virtualizer = useVirtualizer(
6464
get scrollPaddingEnd() { return padding.value.end },
6565
get count() { return props.options.length },
6666
get horizontal() { return rootContext.orientation.value === 'horizontal' },
67-
estimateSize() {
67+
estimateSize(index) {
68+
if (typeof props.estimateSize === 'function')
69+
return props.estimateSize(index)
70+
6871
return props.estimateSize ?? 28
6972
},
7073
getScrollElement() { return parentEl.value },

packages/core/src/Tree/TreeVirtualizer.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export interface TreeVirtualizerProps {
33
/** Number of items rendered outside the visible area */
44
overscan?: number
55
/** Estimated size (in px) of each item */
6-
estimateSize?: number
6+
estimateSize?: number | ((index: number) => number)
77
/** Text content for each item to achieve type-ahead feature */
88
textContent?: (item: Record<string, any>) => string
99
}
@@ -79,7 +79,10 @@ const virtualizer = useVirtualizer(
7979
getItemKey(index) {
8080
return index + rootContext.getKey(rootContext.expandedItems.value[index].value)
8181
},
82-
estimateSize() {
82+
estimateSize(index) {
83+
if (typeof props.estimateSize === 'function')
84+
return props.estimateSize(index)
85+
8386
return props.estimateSize ?? 28
8487
},
8588
getScrollElement() { return parentEl.value },

0 commit comments

Comments
 (0)