Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit d2e9875

Browse files
shemsiunnzhadow
andauthored
feat: use dynamic component to define container element (#229)
Co-authored-by: VWSY (Vigan Shemsiu) <[email protected]>
1 parent a13e411 commit d2e9875

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ npm install vue-virtual-scroll-grid
3232

3333
| Name | Description | Type | Validation |
3434
|----------------------------|-----------------------------------------------------------------------------------|----------------------------------------------------------------|------------------------------------------------------|
35+
| `tag` | The HTML tag used as container element. Default value is `div` | `string` | Any valid HTML tag |
36+
| `probeTag` | The HTML tag used as probe element. Default value is `div` | `string` | Any valid HTML tag |
3537
| `length` | The number of items in the list | `number` | Required, an integer greater than or equal to 0 |
3638
| `pageProvider` | The callback that returns a page of items as a promise. `pageNumber` start with 0 | `(pageNumber: number, pageSize: number) => Promise<unknown[]>` | Required |
3739
| `pageProviderDebounceTime` | Debounce window in milliseconds on the calls to `pageProvider` | `number` | Optional, an integer greater than or equal to 0 |
3840
| `pageSize` | The number of items in a page from the item provider (e.g. a backend API) | `number` | Required, an integer greater than or equal to 1 |
3941
| `scrollTo` | Scroll to a specific item by index | `number` | Optional, an integer from 0 to the `length` prop - 1 |
40-
| `scrollBehavior` | The behavior of `scrollTo`. Default value is `smooth` | `smooth` &#124; `auto` | Optional, a string to be `smooth` or `auto` |
42+
| `scrollBehavior` | The behavior of `scrollTo`. Default value is `smooth` | `smooth` &#124; `auto` | Optional, a string to be `smooth` or `auto` |
4143

4244
Example:
4345

src/Grid.vue

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
2-
<div v-show="length > 0" ref="rootRef" :style="rootStyles">
3-
<div
2+
<component :is="tag" v-show="length > 0" ref="rootRef" :style="rootStyles">
3+
<component
4+
:is="probeTag"
45
:style="{
56
opacity: 0,
67
visibility: 'hidden',
@@ -12,7 +13,7 @@
1213
ref="probeRef"
1314
>
1415
<slot name="probe" />
15-
</div>
16+
</component>
1617

1718
<template
1819
v-for="internalItem in buffer"
@@ -32,7 +33,7 @@
3233
:style="internalItem.style"
3334
/>
3435
</template>
35-
</div>
36+
</component>
3637
</template>
3738

3839
<script lang="ts">
@@ -95,6 +96,16 @@ export default defineComponent({
9596
default: "smooth",
9697
validator: (value: string) => ["smooth", "auto"].includes(value),
9798
},
99+
tag: {
100+
type: String as PropType<string>,
101+
required: false,
102+
default: 'div',
103+
},
104+
probeTag: {
105+
type: String as PropType<string>,
106+
required: false,
107+
default: 'div',
108+
},
98109
},
99110
setup(props) {
100111
// template refs

0 commit comments

Comments
 (0)