Skip to content

feat: add index to renderItem argument #29

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ItemProps<ItemType> extends React.HTMLAttributes<any> {
item?: ItemType;
className?: string;
style?: React.CSSProperties;
renderItem?: (item: ItemType) => React.ReactNode;
renderItem?: (item: ItemType, index: number) => React.ReactNode;
responsive?: boolean;
// https://github.com/ant-design/ant-design/issues/35475
/**
Expand Down Expand Up @@ -66,7 +66,7 @@ function InternalItem<ItemType>(

// ================================ Render ================================
const childNode =
renderItem && item !== UNDEFINED ? renderItem(item) : children;
renderItem && item !== UNDEFINED ? renderItem(item, order) : children;

let overflowStyle: React.CSSProperties | undefined;
if (!invalidate) {
Expand Down
4 changes: 2 additions & 2 deletions src/Overflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface OverflowProps<ItemType> extends React.HTMLAttributes<any> {
itemKey?: React.Key | ((item: ItemType) => React.Key);
/** Used for `responsive`. It will limit render node to avoid perf issue */
itemWidth?: number;
renderItem?: (item: ItemType) => React.ReactNode;
renderItem?: (item: ItemType, index: number) => React.ReactNode;
/** @private Do not use in your production. Render raw node that need wrap Item by developer self */
renderRawItem?: (item: ItemType, index: number) => React.ReactElement;
maxCount?: number | typeof RESPONSIVE | typeof INVALIDATE;
Expand Down Expand Up @@ -172,7 +172,7 @@ function Overflow<ItemType = any>(
);

const mergedRenderItem = useCallback(
renderItem || ((item: ItemType) => item),
renderItem || ((item: ItemType, index: number) => item),
[renderItem],
);

Expand Down