Skip to content

Commit 9f046a1

Browse files
Use scrollIntoView to keep active workflow tab visible (#6077)
> "The watcher that should keep the active workflow tab visible compares the tab’s bounds against the scroll panel’s content element, whose rectangle spans the entire scroll width instead of the visible viewport. As a result, when the active tab starts off-screen, the computed offsets stay ≤ 0 and no corrective scroll occurs, so the selected tab remains hidden." fixes #6057 ------ https://chatgpt.com/codex/tasks/task_e_68efe2b5b4a08330940a20552c1db339
1 parent e1cd88a commit 9f046a1

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/components/topbar/WorkflowTabs.vue

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -228,33 +228,29 @@ const scroll = (direction: number) => {
228228
scrollElement.scrollBy({ left: direction * 20 })
229229
}
230230
231-
// Scroll to active offscreen tab when opened
232-
watch(
233-
() => workflowStore.activeWorkflow,
234-
async () => {
235-
if (!selectedWorkflow.value) return
231+
const ensureActiveTabVisible = async () => {
232+
if (!selectedWorkflow.value) return
236233
237-
await nextTick()
234+
await nextTick()
238235
239-
const activeTabElement = document.querySelector('.p-togglebutton-checked')
240-
if (!activeTabElement || !scrollPanelRef.value) return
241-
242-
const container = scrollPanelRef.value.$el.querySelector(
243-
'.p-scrollpanel-content'
244-
)
245-
if (!container) return
236+
const scrollPanelElement = scrollPanelRef.value?.$el as
237+
| HTMLElement
238+
| undefined
239+
if (!scrollPanelElement) return
246240
247-
const tabRect = activeTabElement.getBoundingClientRect()
248-
const containerRect = container.getBoundingClientRect()
241+
const activeTabElement = scrollPanelElement.querySelector(
242+
'.p-togglebutton-checked'
243+
) as HTMLElement | null
244+
if (!activeTabElement) return
249245
250-
const offsetLeft = tabRect.left - containerRect.left
251-
const offsetRight = tabRect.right - containerRect.right
246+
activeTabElement.scrollIntoView({ block: 'nearest', inline: 'nearest' })
247+
}
252248
253-
if (offsetRight > 0) {
254-
container.scrollBy({ left: offsetRight })
255-
} else if (offsetLeft < 0) {
256-
container.scrollBy({ left: offsetLeft })
257-
}
249+
// Scroll to active offscreen tab when opened
250+
watch(
251+
() => workflowStore.activeWorkflow,
252+
() => {
253+
void ensureActiveTabVisible()
258254
},
259255
{ immediate: true }
260256
)
@@ -285,6 +281,7 @@ watch(scrollContent, (value) => {
285281
void nextTick(() => {
286282
// Force a new check after arrows are updated
287283
scrollState.measure()
284+
void ensureActiveTabVisible()
288285
})
289286
},
290287
{ immediate: true }

0 commit comments

Comments
 (0)