Skip to content

Commit 71c51b8

Browse files
authored
fix(web): keep the model quick-switch menu inside the viewport (#96)
## Related Issue No issue. The problem is described below. ## Problem The web model quick-switch menu opens above its pill with a fixed `160px` minimum height. When the pill sits near the top of the viewport, the menu reached past the viewport edge, so its upper entries could not be scrolled to. The existing test asserted the `160px` value, so it encoded the off-screen behaviour rather than catching it. ## What changed Clamp the menu height to the space actually available above the pill. The `360px` cap is unchanged. The low-space case in the test now asserts the constrained height. This pull request was originally a larger desktop and web branch. #97 landed that work, so only this fix is left; the branch has been reset onto `main`. ## Checklist - [x] I have read the [CONTRIBUTING](https://github.com/PyModel/pythinker-code/blob/main/CONTRIBUTING.md) document. - [x] I have linked a related issue, or explained the problem above. - [x] I have added tests that prove my feature works. - [x] Ran `gen-changesets` skill, or this PR needs no changeset. - [x] Ran `gen-docs` skill, or this PR needs no doc update.
1 parent 7dd68cb commit 71c51b8

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pymodel/pythinker-code": patch
3+
---
4+
5+
Keep the web model quick-switch menu inside the viewport when the composer sits near the top of the window.

apps/pythinker-web/src/components/Composer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ function toggleDropdown(): void {
749749
if (dropdownOpen.value) {
750750
const rect = modelPillRef.value?.getBoundingClientRect();
751751
modelDropdownStyle.value = rect
752-
? { maxHeight: `${Math.min(360, Math.max(160, rect.top - 4 - 12))}px` }
752+
? { maxHeight: `${Math.min(360, Math.max(0, rect.top - 4 - 12))}px` }
753753
: {};
754754
permDropdownOpen.value = false;
755755
document.addEventListener('click', onDocClick, true);

apps/pythinker-web/test/composer.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,11 @@ describe('Composer model dropdown', () => {
408408
const pill = wrapper.get('.model-pill');
409409
const rect = vi.spyOn(pill.element, 'getBoundingClientRect');
410410

411+
// A pill near the top of the viewport used to get a 160px menu that reached
412+
// above the viewport edge, so its upper entries could not be scrolled to.
411413
rect.mockReturnValue({ top: 20 } as DOMRect);
412414
await pill.trigger('click');
413-
expect(wrapper.get('.model-dropdown').element.style.maxHeight).toBe('160px');
415+
expect(wrapper.get('.model-dropdown').element.style.maxHeight).toBe('4px');
414416

415417
rect.mockReturnValue({ top: 300 } as DOMRect);
416418
await pill.trigger('click');

0 commit comments

Comments
 (0)