File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 1
1
import * as React from 'react' ;
2
2
import classNames from 'classnames' ;
3
3
import ResizeObserver from 'rc-resize-observer' ;
4
+ import type { ItemWithIndex } from './Overflow' ;
4
5
import type { ComponentType } from './RawItem' ;
5
6
6
7
// Use shared variable to save bundle size
7
8
const UNDEFINED = undefined ;
8
9
9
10
export interface ItemProps < ItemType > extends React . HTMLAttributes < any > {
10
11
prefixCls : string ;
11
- item ?: ItemType ;
12
+ item ?: ItemWithIndex < ItemType > ;
12
13
className ?: string ;
13
14
style ?: React . CSSProperties ;
14
- renderItem ?: ( item : ItemType ) => React . ReactNode ;
15
+ renderItem ?: ( item : ItemWithIndex < ItemType > ) => React . ReactNode ;
15
16
responsive ?: boolean ;
16
17
// https://github.com/ant-design/ant-design/issues/35475
17
18
/**
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ export { OverflowContext } from './context';
16
16
17
17
export type { ComponentType } from './RawItem' ;
18
18
19
+ export type ItemWithIndex < ItemType > = ItemType & { index ?: number } ;
20
+
19
21
export interface OverflowProps < ItemType > extends React . HTMLAttributes < any > {
20
22
prefixCls ?: string ;
21
23
className ?: string ;
@@ -24,7 +26,7 @@ export interface OverflowProps<ItemType> extends React.HTMLAttributes<any> {
24
26
itemKey ?: React . Key | ( ( item : ItemType ) => React . Key ) ;
25
27
/** Used for `responsive`. It will limit render node to avoid perf issue */
26
28
itemWidth ?: number ;
27
- renderItem ?: ( item : ItemType ) => React . ReactNode ;
29
+ renderItem ?: ( item : ItemWithIndex < ItemType > ) => React . ReactNode ;
28
30
/** @private Do not use in your production. Render raw node that need wrap Item by developer self */
29
31
renderRawItem ?: ( item : ItemType , index : number ) => React . ReactElement ;
30
32
maxCount ?: number | typeof RESPONSIVE | typeof INVALIDATE ;
@@ -341,13 +343,13 @@ function Overflow<ItemType = any>(
341
343
}
342
344
: ( item : ItemType , index : number ) => {
343
345
const key = getKey ( item , index ) ;
344
-
346
+ const propsItem : ItemWithIndex < ItemType > = { ... item , index } ;
345
347
return (
346
348
< Item
347
349
{ ...itemSharedProps }
348
350
order = { index }
349
351
key = { key }
350
- item = { { ... item , index } }
352
+ item = { propsItem }
351
353
renderItem = { mergedRenderItem }
352
354
itemKey = { key }
353
355
registerSize = { registerSize }
Original file line number Diff line number Diff line change @@ -56,8 +56,8 @@ describe('Overflow.Basic', () => {
56
56
const wrapper = mount (
57
57
< Overflow
58
58
data = { testData }
59
- renderItem = { ( item , order ) => {
60
- return `${ item . label } -${ order } -test` ;
59
+ renderItem = { ( item ) => {
60
+ return `${ item . label } -${ item . index } -test` ;
61
61
} }
62
62
/> ,
63
63
) ;
You can’t perform that action at this time.
0 commit comments