fix(ui): use dynamic item height for compact mode dropdowns

Account for 36px items in compact mode vs 40px in normal mode when
calculating menu max-height and options container height.

cc
This commit is contained in:
vicrodh committed 2026-01-29 17:03:25 -06:00
1 parent 5421bb9eb1
commit 669e9dbf4a
1 file changed
+12 -9
+12 -9
View File
@@ -42,8 +42,10 @@
// Menu positioning state // Menu positioning state
let menuPosition = $state<{ top?: string; bottom?: string; left?: string; right?: string }>({}); let menuPosition = $state<{ top?: string; bottom?: string; left?: string; right?: string }>({});
// Item height for calculations (40px option + 0px padding = 40px) // Item height depends on compact mode
const ITEM_HEIGHT = 40; const ITEM_HEIGHT_NORMAL = 40;
const ITEM_HEIGHT_COMPACT = 36;
const itemHeight = $derived(compact ? ITEM_HEIGHT_COMPACT : ITEM_HEIGHT_NORMAL);
const SEARCH_HEIGHT = 48; // search input height including margin const SEARCH_HEIGHT = 48; // search input height including margin
const MENU_PADDING = 8; // 4px top + 4px bottom const MENU_PADDING = 8; // 4px top + 4px bottom
const MAX_VISIBLE_ITEMS = 4; const MAX_VISIBLE_ITEMS = 4;
@@ -204,8 +206,8 @@
// Calculate menu max-height based on whether search is shown // Calculate menu max-height based on whether search is shown
const menuMaxHeight = $derived( const menuMaxHeight = $derived(
showSearch showSearch
? `${SEARCH_HEIGHT + (MAX_VISIBLE_ITEMS * ITEM_HEIGHT) + MENU_PADDING}px` ? `${SEARCH_HEIGHT + (MAX_VISIBLE_ITEMS * itemHeight) + MENU_PADDING}px`
: `${Math.min(options.length, 8) * ITEM_HEIGHT + MENU_PADDING}px` : `${Math.min(options.length, 8) * itemHeight + MENU_PADDING}px`
); );
</script> </script>
@@ -244,7 +246,11 @@
/> />
</div> </div>
{/if} {/if}
<div class="options-container" class:with-search={showSearch}> <div
class="options-container"
class:with-search={showSearch}
style:max-height={showSearch ? `${MAX_VISIBLE_ITEMS * itemHeight}px` : undefined}
>
{#each filteredOptions as option} {#each filteredOptions as option}
<button <button
class="option" class="option"
@@ -369,10 +375,7 @@
min-height: 0; min-height: 0;
} }
.options-container.with-search { /* max-height for .with-search is set via inline style for compact mode support */
/* Fixed height for 4 items when search is shown */
max-height: calc(4 * 40px);
}
.options-container::-webkit-scrollbar { .options-container::-webkit-scrollbar {
width: 6px; width: 6px;