fix: clamp teleported dropdown position to viewport bounds

When neither upward nor downward direction has enough space for the
full menu height, clamp the position so the menu stays within the
viewport instead of overflowing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jin Yi
2026-03-27 13:43:13 +09:00
parent 3e587c7758
commit b09778e879

View File

@@ -178,11 +178,10 @@ function toggleDropdown() {
spaceBelow < MENU_HEIGHT_WITH_GAP && spaceAbove > spaceBelow
if (shouldTeleport) {
if (openUpward.value && rect.top < MENU_HEIGHT_WITH_GAP) {
openUpward.value = false
}
fixedPosition.value = {
top: openUpward.value ? rect.top : rect.bottom,
top: openUpward.value
? Math.max(MENU_HEIGHT_WITH_GAP, rect.top)
: Math.min(rect.bottom, window.innerHeight - MENU_HEIGHT_WITH_GAP),
left: Math.min(rect.right, window.innerWidth - MENU_WIDTH)
}
}