Skip to content

Commit

Permalink
Merge pull request #5791 from matuzalemsteles/LPD-21653
Browse files Browse the repository at this point in the history
feat(@clayui/core): adds the `index` available in the item collection API
  • Loading branch information
matuzalemsteles authored Mar 28, 2024
2 parents 85ce1a2 + 06fc444 commit d80ada3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/clay-core/src/collection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type ChildElement = IReactTypeElement & {

export type ChildrenFunction<T, P> = P extends Array<unknown>
? (item: T, ...args: P) => React.ReactElement
: (item: T) => React.ReactElement;
: (item: T, index?: number) => React.ReactElement;

export interface ICollectionProps<T, P> {
/**
Expand Down
9 changes: 6 additions & 3 deletions packages/clay-core/src/collection/useCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function useCollection<
: (item as T);
const child = Array.isArray(publicApi)
? (children(publicItem, ...publicApi) as ChildElement)
: (children(publicItem) as ChildElement);
: (children(publicItem, index) as ChildElement);

callNestedChild(child);

Expand Down Expand Up @@ -274,7 +274,10 @@ export function useCollection<
publicItem,
...publicApi
) as ChildElement)
: (children(publicItem) as ChildElement);
: (children(
publicItem,
virtual.index
) as ChildElement);

const props = {
'data-index': virtual.index,
Expand Down Expand Up @@ -317,7 +320,7 @@ export function useCollection<
: item;
const child = Array.isArray(publicApi)
? (children(publicItem, ...publicApi) as ChildElement)
: (children(publicItem) as ChildElement);
: (children(publicItem, index) as ChildElement);

const key = getKey(
index,
Expand Down

0 comments on commit d80ada3

Please sign in to comment.