File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ export interface ItemProps<ItemType> extends React.HTMLAttributes<any> {
19
19
invalidate ?: boolean ;
20
20
}
21
21
22
- export default function Item < ItemType > ( props : ItemProps < ItemType > ) {
22
+ function InternalItem < ItemType > (
23
+ props : ItemProps < ItemType > ,
24
+ ref : React . Ref < any > ,
25
+ ) {
23
26
const {
24
27
prefixCls,
25
28
invalidate,
@@ -74,6 +77,7 @@ export default function Item<ItemType>(props: ItemProps<ItemType>) {
74
77
...style ,
75
78
} }
76
79
{ ...restProps }
80
+ ref = { ref }
77
81
>
78
82
{ childNode }
79
83
</ Component >
@@ -93,3 +97,8 @@ export default function Item<ItemType>(props: ItemProps<ItemType>) {
93
97
94
98
return itemNode ;
95
99
}
100
+
101
+ const Item = React . forwardRef ( InternalItem ) ;
102
+ Item . displayName = 'Item' ;
103
+
104
+ export default Item ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export interface RawItemProps extends React.HTMLAttributes<any> {
8
8
children ?: React . ReactNode ;
9
9
}
10
10
11
- export default function RawItem ( props : RawItemProps ) {
11
+ const InternalRawItem = ( props : RawItemProps , ref : React . Ref < any > ) => {
12
12
const context = React . useContext ( OverflowContext ) ;
13
13
14
14
// Render directly when context not provided
@@ -24,10 +24,16 @@ export default function RawItem(props: RawItemProps) {
24
24
return (
25
25
< OverflowContext . Provider value = { null } >
26
26
< Item
27
+ ref = { ref }
27
28
className = { classNames ( contextClassName , className ) }
28
29
{ ...restContext }
29
30
{ ...restProps }
30
31
/>
31
32
</ OverflowContext . Provider >
32
33
) ;
33
- }
34
+ } ;
35
+
36
+ const RawItem = React . forwardRef ( InternalRawItem ) ;
37
+ RawItem . displayName = 'RawItem' ;
38
+
39
+ export default RawItem ;
Original file line number Diff line number Diff line change @@ -17,17 +17,32 @@ describe('Overflow.Raw', () => {
17
17
}
18
18
19
19
it ( 'render node directly' , ( ) => {
20
+ const elements = new Set < HTMLElement > ( ) ;
21
+
20
22
const wrapper = mount (
21
23
< Overflow < ItemType >
22
24
data = { getData ( 1 ) }
23
25
renderRawItem = { item => {
24
- return < Overflow . Item component = "li" > { item . label } </ Overflow . Item > ;
26
+ return (
27
+ < Overflow . Item
28
+ component = "li"
29
+ ref = { ele => {
30
+ elements . add ( ele ) ;
31
+ } }
32
+ >
33
+ { item . label }
34
+ </ Overflow . Item >
35
+ ) ;
25
36
} }
26
37
itemKey = { item => `bamboo-${ item . key } ` }
27
38
component = "ul"
28
39
/> ,
29
40
) ;
30
41
42
+ const elementList = [ ...elements ] ;
43
+ expect ( elementList ) . toHaveLength ( 1 ) ;
44
+ expect ( elementList [ 0 ] instanceof HTMLLIElement ) . toBeTruthy ( ) ;
45
+
31
46
expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
32
47
} ) ;
33
48
You can’t perform that action at this time.
0 commit comments