diff --git a/packages/bruno-app/src/components/RequestTabs/index.js b/packages/bruno-app/src/components/RequestTabs/index.js index d0cd0b459c..0f50f4173f 100644 --- a/packages/bruno-app/src/components/RequestTabs/index.js +++ b/packages/bruno-app/src/components/RequestTabs/index.js @@ -1,4 +1,4 @@ -import React, { useState, useRef } from 'react'; +import React, { useState, useRef, useEffect } from 'react'; import find from 'lodash/find'; import filter from 'lodash/filter'; import classnames from 'classnames'; @@ -13,6 +13,8 @@ import StyledWrapper from './StyledWrapper'; const RequestTabs = () => { const dispatch = useDispatch(); const tabsRef = useRef(); + const tabElementsRef = useRef([]); + const [tabsWidth, setTabsWidth] = useState(0); const [newRequestModalOpen, setNewRequestModalOpen] = useState(false); const tabs = useSelector((state) => state.tabs.tabs); const activeTabUid = useSelector((state) => state.tabs.activeTabUid); @@ -20,6 +22,13 @@ const RequestTabs = () => { const leftSidebarWidth = useSelector((state) => state.app.leftSidebarWidth); const screenWidth = useSelector((state) => state.app.screenWidth); + useEffect(() => { + if (tabElementsRef.current.length > 0) { + const totalWidth = tabElementsRef.current.reduce((acc, el) => acc + el?.offsetWidth || 0, 0); + setTabsWidth(totalWidth + 34); // Add 34 for the (+) icon + } + }, [tabs]); + const getTabClassname = (tab, index) => { return classnames('request-tab select-none', { active: tab.uid === activeTabUid, @@ -50,7 +59,6 @@ const RequestTabs = () => { const collectionRequestTabs = filter(tabs, (t) => t.collectionUid === activeTab.collectionUid); const maxTablistWidth = screenWidth - leftSidebarWidth - 150; - const tabsWidth = collectionRequestTabs.length * 150 + 34; // 34: (+)icon const showChevrons = maxTablistWidth < tabsWidth; const leftSlide = () => { @@ -109,6 +117,7 @@ const RequestTabs = () => { className={getTabClassname(tab, index)} role="tab" onClick={() => handleClick(tab)} + ref={(el) => (tabElementsRef.current[index] = el)} >