Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions apps/website/src/components/workshop/HeaderWorkspaceMenu.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { ArrowLeftRight, Check } from '@lucide/vue'
import { onMounted, ref, useTemplateRef } from 'vue'
import { useEventListener } from '@vueuse/core'
import { ref, useTemplateRef, watch } from 'vue'
import {
DropdownMenuItem,
DropdownMenuPortal,
Expand All @@ -15,6 +16,7 @@ import type { WorkshopSession } from '../../config/workshop-session-state'
import type { Locale } from '../../i18n/translations'
import { t } from '../../i18n/translations'
import { workspaceInitialsOf } from '../../lib/workshop/initials'
import { submenuOffset } from '../../lib/workshop/submenu-offset'
import type { WorkspaceWithRole } from '../../lib/workshop/workspaces'

const {
Expand Down Expand Up @@ -50,14 +52,28 @@ const trigger = useTemplateRef<{ $el: HTMLElement }>('trigger')
const sideOffset = ref(GAP)

// The switcher is a button inside the menu, so a submenu placed beside it lands
// on top of the menu. It is offset to the menu's own left edge instead.
onMounted(() => {
// on top of the menu. It is offset to the menu's own left edge instead, and
// measured each time the list opens, since the menu has a maximum width the
// viewport constrains and its left edge moves when the window does.
function measure() {
const el = trigger.value?.$el
const panel = el?.closest('[data-testid="header-account-menu"]')
if (!el || !panel) return
sideOffset.value =
el.getBoundingClientRect().left - panel.getBoundingClientRect().left + GAP
if (!el) return
const panel = el.closest('[data-testid="header-account-menu"]')
sideOffset.value = submenuOffset(
el.getBoundingClientRect(),
panel?.getBoundingClientRect(),
GAP
)
}

watch(open, (isOpen) => {
if (isOpen) measure()
})
useEventListener(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOULD FIX: This resize measurement can run before Reka/Floating UI applies the parent menu's new --reka-dropdown-menu-content-available-width. Its resize callback calls async computePosition, while this listener reads the old panel width synchronously, so resizing a constrained menu wider can leave the submenu overlapping it (and resizing narrower can leave an oversized gap). Observe the panel's actual resize or measure after its layout settles, and extend the E2E case to resize while the submenu is open; the current test only checks initial placement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, and the fix is written: the window listener is replaced by a ResizeObserver on the panel, so the measurement runs once the new constrained width is in the layout rather than racing computePosition. The end-to-end case now narrows the viewport with the list already open, which is the case it was missing.

It cannot go on this branch: the PR is in the merge queue, so the push is refused. It lands as a follow-up PR against main as soon as this one merges, rather than dequeuing it.


Generated by Claude Code

() => (open.value ? globalThis.window : undefined),
'resize',
measure
)

const itemClass =
'flex w-full cursor-pointer items-center gap-3 rounded-xl px-3 py-3 text-sm text-primary-comfy-canvas outline-none hover:bg-transparency-white-t4 focus-visible:bg-transparency-white-t4'
Expand Down
27 changes: 27 additions & 0 deletions apps/website/src/lib/workshop/submenu-offset.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest'

import { submenuOffset } from './submenu-offset'

describe('submenuOffset', () => {
it.for([
['a button at the right edge of a wide menu', 260, 0, 12, 272],
['a trigger that fills the menu', 0, 0, 12, 12],
['a narrower gap', 100, 0, 8, 108],
// The panel is only at zero when the menu is against the left edge, and
// the offset is the distance between the two, not the trigger's own.
['a menu that has moved with the viewport', 360, 100, 12, 272]
] as const)(
'clears the panel for %s',
([, trigger, panel, gap, expected]) => {
expect(submenuOffset({ left: trigger }, { left: panel }, gap)).toBe(
expected
)
}
)

// Measured before the menu is in the DOM, or outside one entirely: the gap
// alone is what the submenu had before any of this.
it('falls back to the plain gap with no panel to measure', () => {
expect(submenuOffset({ left: 260 }, undefined, 12)).toBe(12)
})
})
16 changes: 16 additions & 0 deletions apps/website/src/lib/workshop/submenu-offset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* How far a submenu has to be pushed to clear the menu its trigger sits in.
*
* A submenu opening to the left of its trigger clears the trigger, not the
* panel around it. Where the trigger is a small button inside a wide menu, the
* difference is the whole menu, and the submenu lands on top of it. Measuring
* to the panel's edge instead follows the menu if its width changes, which a
* pinned number would not.
*/
export function submenuOffset(
trigger: { readonly left: number },
panel: { readonly left: number } | undefined,
gap: number
): number {
return panel ? trigger.left - panel.left + gap : gap
}
Loading