Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/Overflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,19 @@ function Overflow<ItemType = any>(
[renderItem],
);

function updateDisplayCount(count: number, notReady?: boolean) {
function updateDisplayCount(
count: number,
suffixFixedStartVal: number,
notReady?: boolean,
) {
// React 18 will sync render even when the value is same in some case.
// We take `mergedData` as deps which may cause dead loop if it's dynamic generate.
// ref: https://github.com/ant-design/ant-design/issues/36559
if (displayCount === count) {
if (
displayCount === count &&
(suffixFixedStartVal === undefined ||
suffixFixedStartVal === suffixFixedStart)
) {
return;
}

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

onVisibleChange?.(count);
}

if (suffixFixedStartVal !== undefined) {
setSuffixFixedStart(suffixFixedStartVal);
}
}

// ================================= Size =================================
Expand Down Expand Up @@ -233,8 +245,7 @@ function Overflow<ItemType = any>(

// When data count change to 0, reset this since not loop will reach
if (!len) {
updateDisplayCount(0);
setSuffixFixedStart(null);
updateDisplayCount(0, null);
return;
}

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

// Break since data not ready
if (currentItemWidth === undefined) {
updateDisplayCount(i - 1, true);
updateDisplayCount(i - 1, undefined, true);
break;
}

Expand All @@ -263,13 +274,12 @@ function Overflow<ItemType = any>(
totalWidth + getItemWidth(lastIndex)! <= mergedContainerWidth)
) {
// Additional check if match the end
updateDisplayCount(lastIndex);
setSuffixFixedStart(null);
updateDisplayCount(lastIndex, null);
break;
} else if (totalWidth + mergedRestWidth > mergedContainerWidth) {
// Can not hold all the content to show rest
updateDisplayCount(i - 1);
setSuffixFixedStart(
updateDisplayCount(
i - 1,
totalWidth - currentItemWidth - suffixWidth + restWidth,
);
break;
Expand Down