Skip to content

Commit 99b8f3c

Browse files
fix(fitlist): resolve double overflow render issue
1 parent de71ba6 commit 99b8f3c

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-fit-list",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "A headless React component for rendering a single-line list that collapses overflowing items into a +N indicator.",
55
"keywords": [
66
"react",

src/components/FitList.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function FitList<T>({
9999
expanded,
100100
defaultExpanded,
101101
onExpandedChange,
102-
measureOverflowWidth,
102+
measureOverflowWidth: isDefaultOverflowRenderer ? measureOverflowWidth : undefined,
103103
});
104104

105105
const visibleEntries = React.useMemo(() => {
@@ -119,6 +119,11 @@ export function FitList<T>({
119119
.map((item, index) => ({ item, index: startIndex + index }));
120120
}, [collapseFrom, isExpanded, items, visibleItems.length]);
121121

122+
// Avoid mounting a second copy of a custom overflow renderer in the hidden
123+
// measurement tree. Some interactive renderers (for example Radix popovers)
124+
// keep shared state and can open twice when two trigger instances exist.
125+
const shouldRenderMeasuredOverflow = isDefaultOverflowRenderer;
126+
122127
if (items.length === 0) {
123128
return <>{emptyFallback}</>;
124129
}
@@ -256,13 +261,15 @@ export function FitList<T>({
256261
);
257262
})}
258263

259-
<span
260-
ref={overflowMeasureRef}
261-
className={overflowClassName}
262-
style={{ display: "inline-flex", whiteSpace: "nowrap" }}
263-
>
264-
{overflowChildren}
265-
</span>
264+
{shouldRenderMeasuredOverflow ? (
265+
<span
266+
ref={overflowMeasureRef}
267+
className={overflowClassName}
268+
style={{ display: "inline-flex", whiteSpace: "nowrap" }}
269+
>
270+
{overflowChildren}
271+
</span>
272+
) : null}
266273
</div>
267274
</div>
268275
</>

0 commit comments

Comments
 (0)