Skip to content

Commit 9fb26bf

Browse files
authored
fix: Overflow counting process (#26)
1 parent ba77a80 commit 9fb26bf

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/Overflow.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,19 @@ function Overflow<ItemType = any>(
176176
[renderItem],
177177
);
178178

179-
function updateDisplayCount(count: number, notReady?: boolean) {
179+
function updateDisplayCount(
180+
count: number,
181+
suffixFixedStartVal: number,
182+
notReady?: boolean,
183+
) {
180184
// React 18 will sync render even when the value is same in some case.
181185
// We take `mergedData` as deps which may cause dead loop if it's dynamic generate.
182186
// ref: https://github.com/ant-design/ant-design/issues/36559
183-
if (displayCount === count) {
187+
if (
188+
displayCount === count &&
189+
(suffixFixedStartVal === undefined ||
190+
suffixFixedStartVal === suffixFixedStart)
191+
) {
184192
return;
185193
}
186194

@@ -190,6 +198,10 @@ function Overflow<ItemType = any>(
190198

191199
onVisibleChange?.(count);
192200
}
201+
202+
if (suffixFixedStartVal !== undefined) {
203+
setSuffixFixedStart(suffixFixedStartVal);
204+
}
193205
}
194206

195207
// ================================= Size =================================
@@ -233,8 +245,7 @@ function Overflow<ItemType = any>(
233245

234246
// When data count change to 0, reset this since not loop will reach
235247
if (!len) {
236-
updateDisplayCount(0);
237-
setSuffixFixedStart(null);
248+
updateDisplayCount(0, null);
238249
return;
239250
}
240251

@@ -248,7 +259,7 @@ function Overflow<ItemType = any>(
248259

249260
// Break since data not ready
250261
if (currentItemWidth === undefined) {
251-
updateDisplayCount(i - 1, true);
262+
updateDisplayCount(i - 1, undefined, true);
252263
break;
253264
}
254265

@@ -263,13 +274,12 @@ function Overflow<ItemType = any>(
263274
totalWidth + getItemWidth(lastIndex)! <= mergedContainerWidth)
264275
) {
265276
// Additional check if match the end
266-
updateDisplayCount(lastIndex);
267-
setSuffixFixedStart(null);
277+
updateDisplayCount(lastIndex, null);
268278
break;
269279
} else if (totalWidth + mergedRestWidth > mergedContainerWidth) {
270280
// Can not hold all the content to show rest
271-
updateDisplayCount(i - 1);
272-
setSuffixFixedStart(
281+
updateDisplayCount(
282+
i - 1,
273283
totalWidth - currentItemWidth - suffixWidth + restWidth,
274284
);
275285
break;

0 commit comments

Comments
 (0)