Repository navigation
refactor(models): measure the workspace submenu offset on every open #17841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6b4fc0e
fix(models): the workspace list opens beside the account menu again
mariana953 8944534
fix(models): the workspace list follows the menu when the viewport moves
mariana953 5f7610e
test(models): pin the submenu offset to the distance, not the trigger
mariana953 aafd86d
Merge origin/main into mariana/workspace-list-placement
mariana953 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 asynccomputePosition, 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.There was a problem hiding this comment.
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
ResizeObserveron the panel, so the measurement runs once the new constrained width is in the layout rather than racingcomputePosition. 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
mainas soon as this one merges, rather than dequeuing it.Generated by Claude Code