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

Commit

Permalink
feat: new getKey prop (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Sep 29, 2022
1 parent 6d9b9b6 commit 465c2a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ npm install vue-virtual-scroll-grid
| `scrollBehavior` | The behavior of `scrollTo`. Default value is `smooth` | `smooth` | `auto` | Optional, a string to be `smooth` or `auto`, defaults to `smooth` |
| `scrollTo` | Scroll to a specific item by index | `number` | Optional, an integer from 0 to the `length` prop - 1, defaults to 0 |
| `tag` | The HTML tag used as container element. Default value is `div` | `string` | Optional, any valid HTML tag, defaults to `div` |
| `getKey` | The `:key` used on each grid item. Auto-generated, but overwritable via function | `(internalItem: InternalItem) => number \| string` <sup>1</sup>| Optional, any valid Function that returns a `string` or `number` |

<sup>1</sup>
```ts
interface InternalItem {
index: number;
value: unknown | undefined;
style?: { transform: string; gridArea: string };
}
```

Example:

Expand Down
9 changes: 7 additions & 2 deletions src/Grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<template
v-for="internalItem in buffer"
:key="keyPrefix + '.' + internalItem.index"
:key="getKey ? getKey(internalItem) : keyPrefix + '.' + internalItem.index"
>
<slot
v-if="internalItem.value === undefined"
Expand Down Expand Up @@ -52,7 +52,7 @@ import {
fromWindowScroll,
useObservable,
} from "./utilites";
import { PageProvider, pipeline, ScrollAction } from "./pipeline";
import { InternalItem, PageProvider, pipeline, ScrollAction } from "./pipeline";
import { once } from "ramda";
import { VueInstance } from "@vueuse/core";
Expand Down Expand Up @@ -112,6 +112,11 @@ export default defineComponent({
required: false,
default: "div",
},
getKey: {
type: Function as PropType<(internalItem: InternalItem) => number | string>,
required: false,
default: undefined,
},
},
setup(props) {
// template refs
Expand Down

0 comments on commit 465c2a8

Please sign in to comment.