Skip to content

Commit a2e4470

Browse files
author
刘欢
committed
feat:修改index赋值节点
1 parent a25df5a commit a2e4470

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/Item.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import * as React from 'react';
22
import classNames from 'classnames';
33
import ResizeObserver from 'rc-resize-observer';
4+
import type { ItemWithIndex } from './Overflow';
45
import type { ComponentType } from './RawItem';
56

67
// Use shared variable to save bundle size
78
const UNDEFINED = undefined;
89

910
export interface ItemProps<ItemType> extends React.HTMLAttributes<any> {
1011
prefixCls: string;
11-
item?: ItemType;
12+
item?: ItemWithIndex<ItemType>;
1213
className?: string;
1314
style?: React.CSSProperties;
14-
renderItem?: (item: ItemType) => React.ReactNode;
15+
renderItem?: (item: ItemWithIndex<ItemType>) => React.ReactNode;
1516
responsive?: boolean;
1617
// https://github.com/ant-design/ant-design/issues/35475
1718
/**

src/Overflow.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export { OverflowContext } from './context';
1616

1717
export type { ComponentType } from './RawItem';
1818

19+
export type ItemWithIndex<ItemType> = ItemType & { index?: number };
20+
1921
export interface OverflowProps<ItemType> extends React.HTMLAttributes<any> {
2022
prefixCls?: string;
2123
className?: string;
@@ -24,7 +26,7 @@ export interface OverflowProps<ItemType> extends React.HTMLAttributes<any> {
2426
itemKey?: React.Key | ((item: ItemType) => React.Key);
2527
/** Used for `responsive`. It will limit render node to avoid perf issue */
2628
itemWidth?: number;
27-
renderItem?: (item: ItemType) => React.ReactNode;
29+
renderItem?: (item: ItemWithIndex<ItemType>) => React.ReactNode;
2830
/** @private Do not use in your production. Render raw node that need wrap Item by developer self */
2931
renderRawItem?: (item: ItemType, index: number) => React.ReactElement;
3032
maxCount?: number | typeof RESPONSIVE | typeof INVALIDATE;
@@ -341,13 +343,13 @@ function Overflow<ItemType = any>(
341343
}
342344
: (item: ItemType, index: number) => {
343345
const key = getKey(item, index);
344-
346+
const propsItem: ItemWithIndex<ItemType> = { ...item, index };
345347
return (
346348
<Item
347349
{...itemSharedProps}
348350
order={index}
349351
key={key}
350-
item={{ ...item, index }}
352+
item={propsItem}
351353
renderItem={mergedRenderItem}
352354
itemKey={key}
353355
registerSize={registerSize}

tests/index.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ describe('Overflow.Basic', () => {
5656
const wrapper = mount(
5757
<Overflow
5858
data={testData}
59-
renderItem={(item, order) => {
60-
return `${item.label}-${order}-test`;
59+
renderItem={(item) => {
60+
return `${item.label}-${item.index}-test`;
6161
}}
6262
/>,
6363
);

0 commit comments

Comments
 (0)