From 3c1f0fccf49098b8d573f3b038564120c6b7c04b Mon Sep 17 00:00:00 2001 From: Zhou Yuhang <54398705+xquisite0@users.noreply.github.com> Date: Thu, 7 Aug 2025 08:26:59 +0800 Subject: [PATCH] [web] tiling: fix tabs width bug (#1637) --- .../components/TilesPanelTabsSection.tsx | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/web/src/react-tiling/components/TilesPanelTabsSection.tsx b/apps/web/src/react-tiling/components/TilesPanelTabsSection.tsx index a4bdfbb4e..9787a3f97 100644 --- a/apps/web/src/react-tiling/components/TilesPanelTabsSection.tsx +++ b/apps/web/src/react-tiling/components/TilesPanelTabsSection.tsx @@ -1,5 +1,5 @@ import clsx from 'clsx'; -import { useEffect, useRef } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { useDrag, useDrop } from 'react-dnd'; import { getEmptyImage } from 'react-dnd-html5-backend'; @@ -41,6 +41,8 @@ export default function TilesPanelTabsSection({ useDragHighlightContext(); const tabListRef = useRef(null); const tabRightEmptySpaceRef = useRef(null); + const [isStabilizingWidth, setIsStabilizingWidth] = useState(false); + const [stableWidth, setStableWidth] = useState(null); const [{ isOver }, drop] = useDrop< TilesPanelDragItem | TilesPanelDragPanel, void, @@ -107,6 +109,22 @@ export default function TilesPanelTabsSection({ }, }); + useEffect(() => { + const currentWidth = tabListRef.current?.scrollWidth; + + if (currentWidth) { + setStableWidth(currentWidth); + setIsStabilizingWidth(true); + + const timeoutId = setTimeout(() => { + setIsStabilizingWidth(false); + setStableWidth(null); + }, 10); + + return () => clearTimeout(timeoutId); + } + }, [tabs.length]); + const [{ isDragging }, drag, dragPreview] = useDrag< TilesPanelDragPanel, unknown, @@ -181,9 +199,14 @@ export default function TilesPanelTabsSection({ ref={tabListRef} scrollbars="horizontal" size="thin" + style={ + isStabilizingWidth && stableWidth + ? { width: `${stableWidth}px` } + : undefined + } viewportClass="flex items-center" - widthClass="w-fit"> -
+ widthClass={isStabilizingWidth && stableWidth ? 'w-full' : 'w-fit'}> +
{tabs.map((tabItem, index) => { const isActive = mode === 'interactive' && activeTabId === tabItem.id;