From 891c8a047332f7e462e078cb287f4b5271d871a9 Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:56:50 -0500 Subject: [PATCH] fix(a11y): menus fit the space they open into, so a short window no longer pushes items off screen (#35465) --- src/lib/components/common/Dropdown.svelte | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/components/common/Dropdown.svelte b/src/lib/components/common/Dropdown.svelte index 98cb4912e5..de21cd1261 100644 --- a/src/lib/components/common/Dropdown.svelte +++ b/src/lib/components/common/Dropdown.svelte @@ -48,6 +48,7 @@ let settleTimers: number[] = []; let resolvedMaxHeight = maxHeight ?? DEFAULT_MAX_HEIGHT; let lastContentHeight = 0; + let heightConstrained = false; /** Svelte action: moves the node to document.body and keeps it positioned as it resizes */ function portal(node: HTMLElement) { @@ -158,6 +159,12 @@ contentEl.style.bottom = 'auto'; } + const availableHeight = Math.max(0, openAbove ? spaceAbove : spaceBelow); + heightConstrained = contentHeight > availableHeight; + if (heightConstrained) { + resolvedMaxHeight = `min(${effectiveMaxHeight}, ${availableHeight}px)`; + } + if (align === 'end') { let right = window.innerWidth - rect.right; // Shift if overflowing left edge @@ -226,10 +233,10 @@ } contentEl.style.left = `${Math.max(viewport.left + pad, Math.min(preferredLeft, maxLeft))}px`; contentEl.style.right = 'auto'; - resolvedMaxHeight = - contentHeight > availableHeight - ? `min(${effectiveMaxHeight}, ${availableHeight}px)` - : effectiveMaxHeight; + heightConstrained = contentHeight > availableHeight; + resolvedMaxHeight = heightConstrained + ? `min(${effectiveMaxHeight}, ${availableHeight}px)` + : effectiveMaxHeight; contentEl.style.maxHeight = resolvedMaxHeight; } @@ -431,7 +438,7 @@