Skip to content

Commit

Permalink
feat(useVirutalList): expose scrollTo in component (#2397)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Skaliks <eric.skaliks@t-online.de>
  • Loading branch information
Agapanthus and Moerlin committed Jan 3, 2023
1 parent c9a9a92 commit 9f495d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/core/useVirtualList/component.ts
Expand Up @@ -30,11 +30,12 @@ export const UseVirtualList = defineComponent<UseVirtualListProps>({
'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',
Expand Down
2 changes: 2 additions & 0 deletions packages/core/useVirtualList/index.md
Expand Up @@ -101,3 +101,5 @@ const { list, containerProps, wrapperProps } = useVirtualList(
</template>
</UseVirtualList>
```

To scroll to a specific element, the component exposes `scrollTo(index: number) => void`.

0 comments on commit 9f495d6

Please sign in to comment.