diff --git a/src/components/topbar/WorkflowTabs.vue b/src/components/topbar/WorkflowTabs.vue index 0d73629885..80abcfb4f9 100644 --- a/src/components/topbar/WorkflowTabs.vue +++ b/src/components/topbar/WorkflowTabs.vue @@ -234,33 +234,29 @@ const scroll = (direction: number) => { scrollElement.scrollBy({ left: direction * 20 }) } -// Scroll to active offscreen tab when opened -watch( - () => workflowStore.activeWorkflow, - async () => { - if (!selectedWorkflow.value) return +const ensureActiveTabVisible = async () => { + if (!selectedWorkflow.value) return - await nextTick() + await nextTick() - const activeTabElement = document.querySelector('.p-togglebutton-checked') - if (!activeTabElement || !scrollPanelRef.value) return - - const container = scrollPanelRef.value.$el.querySelector( - '.p-scrollpanel-content' - ) - if (!container) return + const scrollPanelElement = scrollPanelRef.value?.$el as + | HTMLElement + | undefined + if (!scrollPanelElement) return - const tabRect = activeTabElement.getBoundingClientRect() - const containerRect = container.getBoundingClientRect() + const activeTabElement = scrollPanelElement.querySelector( + '.p-togglebutton-checked' + ) as HTMLElement | null + if (!activeTabElement) return - const offsetLeft = tabRect.left - containerRect.left - const offsetRight = tabRect.right - containerRect.right + activeTabElement.scrollIntoView({ block: 'nearest', inline: 'nearest' }) +} - if (offsetRight > 0) { - container.scrollBy({ left: offsetRight }) - } else if (offsetLeft < 0) { - container.scrollBy({ left: offsetLeft }) - } +// Scroll to active offscreen tab when opened +watch( + () => workflowStore.activeWorkflow, + () => { + void ensureActiveTabVisible() }, { immediate: true } ) @@ -291,6 +287,7 @@ watch(scrollContent, (value) => { void nextTick(() => { // Force a new check after arrows are updated scrollState.measure() + void ensureActiveTabVisible() }) }, { immediate: true }