diff --git a/src/components/Dashboard/common/DashboardTabs.jsx b/src/components/Dashboard/common/DashboardTabs.jsx index 8f02b325..41deb686 100644 --- a/src/components/Dashboard/common/DashboardTabs.jsx +++ b/src/components/Dashboard/common/DashboardTabs.jsx @@ -469,8 +469,6 @@ const useActiveTabStickyScroll = (activeTabId, tabs) => { const listRef = useRef(null) const cloneRef = useRef(null) const lineRef = useRef(null) - const prevTabCountRef = useRef(tabs.length) - const pendingScrollTabIdRef = useRef(null) const tabLayoutKey = `${activeTabId}:${tabs.map((tab) => `${tab.id}:${tab.title || ''}`).join('|')}` useLayoutEffect(() => { @@ -509,21 +507,6 @@ const useActiveTabStickyScroll = (activeTabId, tabs) => { } }, [tabLayoutKey]) - useEffect(() => { - const lastTab = tabs[tabs.length - 1] - if ( - tabs.length === prevTabCountRef.current + 1 && - lastTab?.id === activeTabId - ) { - pendingScrollTabIdRef.current = lastTab.id - } - prevTabCountRef.current = tabs.length - - if (!lastTab || pendingScrollTabIdRef.current !== lastTab.id) { - return undefined - } - }, [activeTabId, tabs]) - return { rootRef, listRef, cloneRef, lineRef } } @@ -533,6 +516,7 @@ const DashboardTabs = () => { activeTabId, selectTab, addTab, + registerTabStripRoot, closeTab, reorderTabs, handleTabDragStart, @@ -699,33 +683,13 @@ const DashboardTabs = () => { selectTab(tabs[nextIndex].id) } - const handleAddTab = () => { - addTab() - - const scrollEl = rootRef.current?.querySelector( - '.simplebar-content-wrapper' - ) - - if (!scrollEl) return - - let lastMaxScrollLeft = scrollEl.scrollWidth - scrollEl.clientWidth - let unchangedChecks = 0 - - const interval = setInterval(() => { - const maxScrollLeft = scrollEl.scrollWidth - scrollEl.clientWidth - if (maxScrollLeft !== lastMaxScrollLeft) { - scrollEl.scrollLeft = maxScrollLeft - lastMaxScrollLeft = maxScrollLeft - unchangedChecks = 0 - } else { - unchangedChecks++ - } - - if (unchangedChecks >= 15) { - clearInterval(interval) - } - }, 10) - } + const setRootRef = useCallback( + (element) => { + rootRef.current = element + registerTabStripRoot(element) + }, + [registerTabStripRoot] + ) const isReordering = draggedValue != null || dropTarget != null const activeTab = tabs.find((tab) => tab.id === activeTabId) @@ -775,7 +739,7 @@ const DashboardTabs = () => { return ( {