@@ -6,22 +6,23 @@ import Item from './Item';
66import { useBatchFrameState } from './hooks/useBatchFrameState' ;
77import RawItem from './RawItem' ;
88
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 ;
1516
16- invalidate : boolean ;
17+ invalidate : boolean ;
1718
18- // Item Usage
19- item ?: any ;
20- itemKey ?: React . Key ;
19+ // Item Usage
20+ item ?: any ;
21+ itemKey ?: React . Key ;
2122
22- // Rest Usage
23- className ?: string ;
24- } > ( null ) ;
23+ // Rest Usage
24+ className ?: string ;
25+ } > ( null ) ;
2526
2627const RESPONSIVE = 'responsive' as const ;
2728const INVALIDATE = 'invalidate' as const ;
@@ -90,7 +91,7 @@ function Overflow<ItemType = any>(
9091
9192 const createUseState = useBatchFrameState ( ) ;
9293
93- const fullySSR = ssr === 'full'
94+ const fullySSR = ssr === 'full' ;
9495
9596 const [ containerWidth , setContainerWidth ] = createUseState < number > ( null ) ;
9697 const mergedContainerWidth = containerWidth || 0 ;
@@ -106,13 +107,13 @@ function Overflow<ItemType = any>(
106107 const [ suffixFixedStart , setSuffixFixedStart ] = useState < number > ( null ) ;
107108
108109 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+ }
113114
114- return displayCount || 0 ;
115- } , [ displayCount , containerWidth ] ) ;
115+ return displayCount || 0 ;
116+ } , [ displayCount , containerWidth ] ) ;
116117
117118 const [ restReady , setRestReady ] = useState ( false ) ;
118119
@@ -241,8 +242,11 @@ function Overflow<ItemType = any>(
241242 totalWidth += currentItemWidth ;
242243
243244 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 )
246250 ) {
247251 // Additional check if match the end
248252 updateDisplayCount ( lastIndex ) ;
@@ -255,11 +259,6 @@ function Overflow<ItemType = any>(
255259 totalWidth - currentItemWidth - suffixWidth + restWidth ,
256260 ) ;
257261 break ;
258- } else if ( i === lastIndex ) {
259- // Reach the end
260- updateDisplayCount ( lastIndex ) ;
261- setSuffixFixedStart ( totalWidth - suffixWidth ) ;
262- break ;
263262 }
264263 }
265264
@@ -425,9 +424,9 @@ type FilledOverflowType = ForwardOverflowType & {
425424
426425ForwardOverflow . displayName = 'Overflow' ;
427426
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 ;
431430
432431// Convert to generic type
433- export default ( ForwardOverflow as unknown ) as FilledOverflowType ;
432+ export default ForwardOverflow as unknown as FilledOverflowType ;
0 commit comments