@@ -130,14 +130,19 @@ function Overflow<ItemType = any>(
130130 }
131131
132132 // ================================ Effect ================================
133+ function getItemWidth ( index : number ) {
134+ return itemWidths . get ( getKey ( mergedData [ index ] , index ) ) ;
135+ }
136+
133137 React . useLayoutEffect ( ( ) => {
134138 if ( containerWidth && mergedRestWidth && mergedData ) {
135139 let totalWidth = 0 ;
136140
137141 const len = mergedData . length ;
142+ const lastIndex = len - 1 ;
138143
139144 for ( let i = 0 ; i < len ; i += 1 ) {
140- const currentItemWidth = itemWidths . get ( getKey ( mergedData [ i ] , i ) ) ;
145+ const currentItemWidth = getItemWidth ( i ) ;
141146
142147 // Break since data not ready
143148 if ( currentItemWidth === undefined ) {
@@ -148,11 +153,21 @@ function Overflow<ItemType = any>(
148153 // Find best match
149154 totalWidth += currentItemWidth ;
150155
151- if ( totalWidth + mergedRestWidth > containerWidth ) {
156+ if (
157+ ( i === lastIndex - 1 &&
158+ totalWidth + getItemWidth ( lastIndex ) ! <= containerWidth ) ||
159+ i === lastIndex
160+ ) {
161+ // Additional check if match the end
162+ updateDisplayCount ( lastIndex ) ;
163+ break ;
164+ } else if ( totalWidth + mergedRestWidth > containerWidth ) {
165+ // Can not hold all the content to show rest
152166 updateDisplayCount ( i - 1 ) ;
153167 break ;
154- } else if ( i === len - 1 ) {
155- updateDisplayCount ( len - 1 ) ;
168+ } else if ( i === lastIndex ) {
169+ // Reach the end
170+ updateDisplayCount ( lastIndex ) ;
156171 break ;
157172 }
158173 }
0 commit comments