Skip to content

Commit

Permalink
Merge pull request #496 from inokawa/svelte-index
Browse files Browse the repository at this point in the history
Pass index to slot of Svelte VList
  • Loading branch information
inokawa authored Aug 14, 2024
2 parents 534b872 + 6965192 commit 9b791d0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/svelte/VList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import ListItem from "./ListItem.svelte";
// https://github.com/sveltejs/rfcs/pull/38
interface $$Slots {
default: { item: T; index: number };
}
interface $$Props extends HTMLAttributes<HTMLDivElement> {
/**
* The data items rendered by this component.
Expand Down Expand Up @@ -222,16 +225,16 @@
bind:this={containerRef}
style={`${containerStyle} ${dynamicContainerStyle}`}
>
{#each items as item, index (getKey(item, index + extendedRange[0]))}
{#each items as item, i (getKey(item, i + extendedRange[0]))}
{@const index = i + extendedRange[0]}
<ListItem
index={index + extendedRange[0]}
offset={rerender &&
virtualizer[GET_ITEM_OFFSET](index + extendedRange[0])}
hide={rerender && virtualizer[IS_ITEM_HIDDEN](index + extendedRange[0])}
{index}
offset={rerender && virtualizer[GET_ITEM_OFFSET](index)}
hide={rerender && virtualizer[IS_ITEM_HIDDEN](index)}
{horizontal}
resizer={virtualizer[OBSERVE_ITEM_RESIZE]}
>
<slot {item} />
<slot {item} {index} />
</ListItem>
{/each}
</div>
Expand Down

0 comments on commit 9b791d0

Please sign in to comment.