File tree Expand file tree Collapse file tree 3 files changed +38
-27
lines changed Expand file tree Collapse file tree 3 files changed +38
-27
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ function renderRest(items: ItemType[]) {
47
47
48
48
const Demo = ( ) => {
49
49
const [ responsive , setResponsive ] = React . useState ( true ) ;
50
- const [ data , setData ] = React . useState ( createData ( 2 ) ) ;
50
+ const [ data , setData ] = React . useState ( createData ( 1 ) ) ;
51
51
52
52
return (
53
53
< div style = { { padding : 32 } } >
@@ -80,7 +80,7 @@ const Demo = () => {
80
80
style = { {
81
81
border : '5px solid green' ,
82
82
padding : 8 ,
83
- width : 100 ,
83
+ maxWidth : 300 ,
84
84
marginTop : 32 ,
85
85
} }
86
86
>
Original file line number Diff line number Diff line change @@ -185,10 +185,9 @@ function Overflow<ItemType = any>(
185
185
// We take `mergedData` as deps which may cause dead loop if it's dynamic generate.
186
186
// ref: https://github.com/ant-design/ant-design/issues/36559
187
187
if (
188
- displayCount === count
189
- // displayCount === count &&
190
- // (suffixFixedStartVal === undefined ||
191
- // suffixFixedStartVal === suffixFixedStart)
188
+ displayCount === count &&
189
+ ( suffixFixedStartVal === undefined ||
190
+ suffixFixedStartVal === suffixFixedStart )
192
191
) {
193
192
return ;
194
193
}
@@ -207,7 +206,6 @@ function Overflow<ItemType = any>(
207
206
208
207
// ================================= Size =================================
209
208
function onOverflowResize ( _ : object , element : HTMLElement ) {
210
- console . log ( 'resize overflow' ) ;
211
209
setContainerWidth ( element . clientWidth ) ;
212
210
}
213
211
@@ -239,7 +237,6 @@ function Overflow<ItemType = any>(
239
237
}
240
238
241
239
useLayoutEffect ( ( ) => {
242
- console . log ( 'Effect:' , mergedContainerWidth , mergedRestWidth , mergedData ) ;
243
240
if ( mergedContainerWidth && mergedRestWidth && mergedData ) {
244
241
let totalWidth = suffixWidth ;
245
242
Original file line number Diff line number Diff line change @@ -34,24 +34,28 @@ describe('Overflow.github', () => {
34
34
jest . useRealTimers ( ) ;
35
35
} ) ;
36
36
37
- const clientWidths = {
37
+ const widths = {
38
38
'rc-overflow' : 100 ,
39
+ 'rc-overflow-item' : 90 ,
40
+ } ;
41
+
42
+ const propDef = {
43
+ get ( ) {
44
+ let targetWidth = 0 ;
45
+ Object . keys ( widths ) . forEach ( key => {
46
+ if ( this . className . includes ( key ) ) {
47
+ targetWidth = widths [ key ] ;
48
+ }
49
+ } ) ;
50
+
51
+ return targetWidth ;
52
+ } ,
39
53
} ;
40
54
41
55
beforeAll ( ( ) => {
42
56
spyElementPrototypes ( HTMLDivElement , {
43
- clientWidth : {
44
- get ( ) {
45
- let targetWidth = 0 ;
46
- Object . keys ( clientWidths ) . forEach ( key => {
47
- if ( this . className . includes ( key ) ) {
48
- targetWidth = clientWidths [ key ] ;
49
- }
50
- } ) ;
51
-
52
- return targetWidth ;
53
- } ,
54
- } ,
57
+ clientWidth : propDef ,
58
+ offsetWidth : propDef ,
55
59
} ) ;
56
60
} ) ;
57
61
@@ -75,19 +79,29 @@ describe('Overflow.github', () => {
75
79
/> ,
76
80
) ;
77
81
78
- // width resize
82
+ // width & rest resize
79
83
await triggerResize ( container . querySelector ( '.rc-overflow' ) ) ;
80
-
81
- setTimeout ( ( ) => {
82
- console . log ( 2333 ) ;
83
- } , 1000 ) ;
84
+ await triggerResize ( container . querySelector ( '.rc-overflow-item-rest' ) ) ;
84
85
85
86
act ( ( ) => {
86
87
jest . runAllTimers ( ) ;
87
88
} ) ;
89
+
90
+ const items = Array . from (
91
+ container . querySelectorAll < HTMLDivElement > (
92
+ '.rc-overflow-item:not(.rc-overflow-item-rest)' ,
93
+ ) ,
94
+ ) ;
95
+
96
+ for ( let i = 0 ; i < items . length ; i += 1 ) {
97
+ await triggerResize ( items [ i ] ) ;
98
+ }
88
99
act ( ( ) => {
89
100
jest . runAllTimers ( ) ;
90
101
} ) ;
91
- console . log ( jest . getTimerCount ( ) ) ;
102
+
103
+ expect ( container . querySelector ( '.rc-overflow-item-rest' ) ) . toHaveStyle ( {
104
+ opacity : 1 ,
105
+ } ) ;
92
106
} ) ;
93
107
} ) ;
You can’t perform that action at this time.
0 commit comments