@@ -55,6 +55,9 @@ export interface OverflowProps<ItemType> extends React.HTMLAttributes<any> {
55
55
56
56
/** @private This API may be refactor since not well design */
57
57
onVisibleChange ?: ( visibleCount : number ) => void ;
58
+
59
+ /** When set to `full`, ssr will render full items by default and remove at client side */
60
+ ssr ?: 'full' ;
58
61
}
59
62
60
63
function defaultRenderRest < ItemType > ( omittedItems : ItemType [ ] ) {
@@ -72,6 +75,7 @@ function Overflow<ItemType = any>(
72
75
renderRawItem,
73
76
itemKey,
74
77
itemWidth = 10 ,
78
+ ssr,
75
79
style,
76
80
className,
77
81
maxCount,
@@ -86,7 +90,9 @@ function Overflow<ItemType = any>(
86
90
87
91
const createUseState = useBatchFrameState ( ) ;
88
92
89
- const [ containerWidth , setContainerWidth ] = createUseState ( 0 ) ;
93
+ const [ containerWidth , setContainerWidth ] = createUseState < number > ( null ) ;
94
+ const mergedContainerWidth = containerWidth || 0 ;
95
+
90
96
const [ itemWidths , setItemWidths ] = createUseState (
91
97
new Map < React . Key , number > ( ) ,
92
98
) ;
@@ -119,7 +125,14 @@ function Overflow<ItemType = any>(
119
125
let items = data ;
120
126
121
127
if ( isResponsive ) {
122
- items = data . slice ( 0 , Math . min ( data . length , containerWidth / itemWidth ) ) ;
128
+ if ( containerWidth === null && ssr === 'full' ) {
129
+ items = data ;
130
+ } else {
131
+ items = data . slice (
132
+ 0 ,
133
+ Math . min ( data . length , mergedContainerWidth / itemWidth ) ,
134
+ ) ;
135
+ }
123
136
} else if ( typeof maxCount === 'number' ) {
124
137
items = data . slice ( 0 , maxCount ) ;
125
138
}
@@ -192,7 +205,7 @@ function Overflow<ItemType = any>(
192
205
}
193
206
194
207
React . useLayoutEffect ( ( ) => {
195
- if ( containerWidth && mergedRestWidth && mergedData ) {
208
+ if ( mergedContainerWidth && mergedRestWidth && mergedData ) {
196
209
let totalWidth = suffixWidth ;
197
210
198
211
const len = mergedData . length ;
@@ -219,13 +232,13 @@ function Overflow<ItemType = any>(
219
232
220
233
if (
221
234
i === lastIndex - 1 &&
222
- totalWidth + getItemWidth ( lastIndex ) ! <= containerWidth
235
+ totalWidth + getItemWidth ( lastIndex ) ! <= mergedContainerWidth
223
236
) {
224
237
// Additional check if match the end
225
238
updateDisplayCount ( lastIndex ) ;
226
239
setSuffixFixedStart ( null ) ;
227
240
break ;
228
- } else if ( totalWidth + mergedRestWidth > containerWidth ) {
241
+ } else if ( totalWidth + mergedRestWidth > mergedContainerWidth ) {
229
242
// Can not hold all the content to show rest
230
243
updateDisplayCount ( i - 1 ) ;
231
244
setSuffixFixedStart (
@@ -240,11 +253,18 @@ function Overflow<ItemType = any>(
240
253
}
241
254
}
242
255
243
- if ( suffix && getItemWidth ( 0 ) + suffixWidth > containerWidth ) {
256
+ if ( suffix && getItemWidth ( 0 ) + suffixWidth > mergedContainerWidth ) {
244
257
setSuffixFixedStart ( null ) ;
245
258
}
246
259
}
247
- } , [ containerWidth , itemWidths , restWidth , suffixWidth , getKey , mergedData ] ) ;
260
+ } , [
261
+ mergedContainerWidth ,
262
+ itemWidths ,
263
+ restWidth ,
264
+ suffixWidth ,
265
+ getKey ,
266
+ mergedData ,
267
+ ] ) ;
248
268
249
269
// ================================ Render ================================
250
270
const displayRest = restReady && ! ! omittedItems . length ;
0 commit comments