@@ -6,22 +6,23 @@ import Item from './Item';
6
6
import { useBatchFrameState } from './hooks/useBatchFrameState' ;
7
7
import RawItem from './RawItem' ;
8
8
9
- export const OverflowContext = React . createContext < {
10
- prefixCls : string ;
11
- responsive : boolean ;
12
- order : number ;
13
- registerSize : ( key : React . Key , width : number | null ) => void ;
14
- display : boolean ;
9
+ export const OverflowContext =
10
+ React . createContext < {
11
+ prefixCls : string ;
12
+ responsive : boolean ;
13
+ order : number ;
14
+ registerSize : ( key : React . Key , width : number | null ) => void ;
15
+ display : boolean ;
15
16
16
- invalidate : boolean ;
17
+ invalidate : boolean ;
17
18
18
- // Item Usage
19
- item ?: any ;
20
- itemKey ?: React . Key ;
19
+ // Item Usage
20
+ item ?: any ;
21
+ itemKey ?: React . Key ;
21
22
22
- // Rest Usage
23
- className ?: string ;
24
- } > ( null ) ;
23
+ // Rest Usage
24
+ className ?: string ;
25
+ } > ( null ) ;
25
26
26
27
const RESPONSIVE = 'responsive' as const ;
27
28
const INVALIDATE = 'invalidate' as const ;
@@ -90,7 +91,7 @@ function Overflow<ItemType = any>(
90
91
91
92
const createUseState = useBatchFrameState ( ) ;
92
93
93
- const fullySSR = ssr === 'full'
94
+ const fullySSR = ssr === 'full' ;
94
95
95
96
const [ containerWidth , setContainerWidth ] = createUseState < number > ( null ) ;
96
97
const mergedContainerWidth = containerWidth || 0 ;
@@ -106,13 +107,13 @@ function Overflow<ItemType = any>(
106
107
const [ suffixFixedStart , setSuffixFixedStart ] = useState < number > ( null ) ;
107
108
108
109
const [ displayCount , setDisplayCount ] = useState ( null ) ;
109
- const mergedDisplayCount = React . useMemo ( ( ) => {
110
- if ( displayCount === null && fullySSR ) {
111
- return Number . MAX_SAFE_INTEGER ;
112
- }
110
+ const mergedDisplayCount = React . useMemo ( ( ) => {
111
+ if ( displayCount === null && fullySSR ) {
112
+ return Number . MAX_SAFE_INTEGER ;
113
+ }
113
114
114
- return displayCount || 0 ;
115
- } , [ displayCount , containerWidth ] ) ;
115
+ return displayCount || 0 ;
116
+ } , [ displayCount , containerWidth ] ) ;
116
117
117
118
const [ restReady , setRestReady ] = useState ( false ) ;
118
119
@@ -241,8 +242,11 @@ function Overflow<ItemType = any>(
241
242
totalWidth += currentItemWidth ;
242
243
243
244
if (
244
- i === lastIndex - 1 &&
245
- totalWidth + getItemWidth ( lastIndex ) ! <= mergedContainerWidth
245
+ // Only one means `totalWidth` is the final width
246
+ ( lastIndex === 0 && totalWidth <= mergedContainerWidth ) ||
247
+ // Last two width will be the final width
248
+ ( i === lastIndex - 1 &&
249
+ totalWidth + getItemWidth ( lastIndex ) ! <= mergedContainerWidth )
246
250
) {
247
251
// Additional check if match the end
248
252
updateDisplayCount ( lastIndex ) ;
@@ -255,11 +259,6 @@ function Overflow<ItemType = any>(
255
259
totalWidth - currentItemWidth - suffixWidth + restWidth ,
256
260
) ;
257
261
break ;
258
- } else if ( i === lastIndex ) {
259
- // Reach the end
260
- updateDisplayCount ( lastIndex ) ;
261
- setSuffixFixedStart ( totalWidth - suffixWidth ) ;
262
- break ;
263
262
}
264
263
}
265
264
@@ -425,9 +424,9 @@ type FilledOverflowType = ForwardOverflowType & {
425
424
426
425
ForwardOverflow . displayName = 'Overflow' ;
427
426
428
- ( ( ForwardOverflow as unknown ) as FilledOverflowType ) . Item = RawItem ;
429
- ( ( ForwardOverflow as unknown ) as FilledOverflowType ) . RESPONSIVE = RESPONSIVE ;
430
- ( ( ForwardOverflow as unknown ) as FilledOverflowType ) . INVALIDATE = INVALIDATE ;
427
+ ( ForwardOverflow as unknown as FilledOverflowType ) . Item = RawItem ;
428
+ ( ForwardOverflow as unknown as FilledOverflowType ) . RESPONSIVE = RESPONSIVE ;
429
+ ( ForwardOverflow as unknown as FilledOverflowType ) . INVALIDATE = INVALIDATE ;
431
430
432
431
// Convert to generic type
433
- export default ( ForwardOverflow as unknown ) as FilledOverflowType ;
432
+ export default ForwardOverflow as unknown as FilledOverflowType ;
0 commit comments