Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(useVirtualList): horizontal list #2310

Merged
merged 5 commits into from Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/useVirtualList/component.ts
Expand Up @@ -35,7 +35,8 @@ export const UseVirtualList = defineComponent<UseVirtualListProps>({

const { list, containerProps, wrapperProps } = useVirtualList(listRef, props.options)

containerProps.style.height = props.height || '300px'
typeof containerProps.style === 'object' && !Array.isArray(containerProps.style) && (containerProps.style.height = props.height || '300px')

return () => h('div',
{ ...containerProps },
[
Expand Down
30 changes: 29 additions & 1 deletion packages/core/useVirtualList/index.md
Expand Up @@ -27,9 +27,10 @@ const { list, containerProps, wrapperProps } = useVirtualList(
| State | Type | Description |
|------------|----------|-------------------------------------------------------------------------------------------------|
| itemHeight | `number` | ensure that the total height of the `wrapper` element is calculated correctly.* |
| itemWidth | `number` | ensure that the total width of the `wrapper` element is calculated correctly.* |
| overscan | `number` | number of pre-rendered DOM nodes. Prevents whitespace between items if you scroll very quickly. |

\* The `itemHeight` must be kept in sync with the height of each row rendered. If you are seeing extra whitespace or jitter when scrolling to the bottom of the list, ensure the `itemHeight` is the same height as the row.
\* The `itemHeight` or `itemWidth` must be kept in sync with the height of each row rendered. If you are seeing extra whitespace or jitter when scrolling to the bottom of the list, ensure the `itemHeight` or `itemWidth` is the same height as the row.

### Reactive list

Expand Down Expand Up @@ -63,6 +64,33 @@ const { list, containerProps, wrapperProps } = useVirtualList(
</template>
```

### Horizontal list

```typescript
import { useVirtualList } from '@vueuse/core'

const allItems = Array.from(Array(99999).keys())

const { list, containerProps, wrapperProps } = useVirtualList(
allItems,
{
itemWidth: 200,
},
)
```

```html
<template>
<div v-bind="containerProps" style="height: 300px">
<div v-bind="wrapperProps">
<div v-for="item in list" :key="item.index" style="width: 200px">
Row: {{ item.data }}
</div>
</div>
</div>
</template>
```

## Component Usage

```html
Expand Down