From 9f495d625abbda4bea7a1704c7592d583c320abf Mon Sep 17 00:00:00 2001 From: Eric Skaliks Date: Tue, 3 Jan 2023 14:17:50 +0100 Subject: [PATCH] feat(useVirutalList): expose `scrollTo` in component (#2397) Co-authored-by: Eric Skaliks --- packages/core/useVirtualList/component.ts | 7 ++++--- packages/core/useVirtualList/index.md | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/core/useVirtualList/component.ts b/packages/core/useVirtualList/component.ts index 158e6d2b558..c39f97af060 100644 --- a/packages/core/useVirtualList/component.ts +++ b/packages/core/useVirtualList/component.ts @@ -30,11 +30,12 @@ export const UseVirtualList = defineComponent({ 'options', 'height', ] as unknown as undefined, - setup(props, { slots }) { + setup(props, { slots, expose }) { const { list: listRef } = toRefs(props) - const { list, containerProps, wrapperProps } = useVirtualList(listRef, props.options) - + const { list, containerProps, wrapperProps, scrollTo } = useVirtualList(listRef, props.options) + expose({ scrollTo }) + typeof containerProps.style === 'object' && !Array.isArray(containerProps.style) && (containerProps.style.height = props.height || '300px') return () => h('div', diff --git a/packages/core/useVirtualList/index.md b/packages/core/useVirtualList/index.md index e96bb844c4d..c17626009c7 100644 --- a/packages/core/useVirtualList/index.md +++ b/packages/core/useVirtualList/index.md @@ -101,3 +101,5 @@ const { list, containerProps, wrapperProps } = useVirtualList( ``` + +To scroll to a specific element, the component exposes `scrollTo(index: number) => void`.