@@ -130,14 +130,19 @@ function Overflow<ItemType = any>(
130
130
}
131
131
132
132
// ================================ Effect ================================
133
+ function getItemWidth ( index : number ) {
134
+ return itemWidths . get ( getKey ( mergedData [ index ] , index ) ) ;
135
+ }
136
+
133
137
React . useLayoutEffect ( ( ) => {
134
138
if ( containerWidth && mergedRestWidth && mergedData ) {
135
139
let totalWidth = 0 ;
136
140
137
141
const len = mergedData . length ;
142
+ const lastIndex = len - 1 ;
138
143
139
144
for ( let i = 0 ; i < len ; i += 1 ) {
140
- const currentItemWidth = itemWidths . get ( getKey ( mergedData [ i ] , i ) ) ;
145
+ const currentItemWidth = getItemWidth ( i ) ;
141
146
142
147
// Break since data not ready
143
148
if ( currentItemWidth === undefined ) {
@@ -148,11 +153,21 @@ function Overflow<ItemType = any>(
148
153
// Find best match
149
154
totalWidth += currentItemWidth ;
150
155
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
152
166
updateDisplayCount ( i - 1 ) ;
153
167
break ;
154
- } else if ( i === len - 1 ) {
155
- updateDisplayCount ( len - 1 ) ;
168
+ } else if ( i === lastIndex ) {
169
+ // Reach the end
170
+ updateDisplayCount ( lastIndex ) ;
156
171
break ;
157
172
}
158
173
}
0 commit comments