From 5421bb9eb18eb8067362cc12cfe8aaf65cfeb0d9 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:57:04 -0600 Subject: [PATCH] fix(ui): rewrite Dropdown with smart positioning and search - Add search input when options > 5 - Implement smart positioning to dodge viewport edges - Fixed height showing 4 items when searchable - Add scroll snap for clean item display - Recalculate position on scroll/resize cc --- src/lib/components/Dropdown.svelte | 282 +++++++++++++++++++++++++---- 1 file changed, 242 insertions(+), 40 deletions(-) diff --git a/src/lib/components/Dropdown.svelte b/src/lib/components/Dropdown.svelte index 6efa9d2c9..38f3b25b0 100644 --- a/src/lib/components/Dropdown.svelte +++ b/src/lib/components/Dropdown.svelte @@ -1,5 +1,5 @@ @@ -164,9 +311,8 @@ .menu { position: absolute; - top: 100%; - left: 0; margin-top: 4px; + margin-bottom: 4px; min-width: 170px; width: max-content; background-color: var(--bg-tertiary); @@ -174,27 +320,9 @@ padding: 4px 0; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); z-index: 10000; - max-height: 300px; - overflow-y: auto; - scrollbar-width: thin; - scrollbar-color: var(--text-muted) transparent; - } - - .menu::-webkit-scrollbar { - width: 8px; - } - - .menu::-webkit-scrollbar-track { - background: transparent; - } - - .menu::-webkit-scrollbar-thumb { - background: var(--text-muted); - border-radius: 9999px; - } - - .menu::-webkit-scrollbar-thumb:hover { - background: var(--text-secondary); + display: flex; + flex-direction: column; + overflow: hidden; } .menu.expand-left { @@ -202,9 +330,73 @@ right: 0; } + .search-container { + display: flex; + align-items: center; + gap: 8px; + padding: 8px 12px; + border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.1)); + flex-shrink: 0; + } + + .search-container :global(.search-icon) { + color: var(--text-muted); + flex-shrink: 0; + } + + .search-input { + flex: 1; + background: transparent; + border: none; + outline: none; + color: var(--text-primary); + font-size: 13px; + padding: 0; + min-width: 0; + } + + .search-input::placeholder { + color: var(--text-muted); + } + + .options-container { + overflow-y: auto; + overflow-x: hidden; + scroll-snap-type: y mandatory; + scrollbar-width: thin; + scrollbar-color: var(--text-muted) transparent; + flex: 1; + min-height: 0; + } + + .options-container.with-search { + /* Fixed height for 4 items when search is shown */ + max-height: calc(4 * 40px); + } + + .options-container::-webkit-scrollbar { + width: 6px; + } + + .options-container::-webkit-scrollbar-track { + background: transparent; + } + + .options-container::-webkit-scrollbar-thumb { + background: var(--text-muted); + border-radius: 9999px; + } + + .options-container::-webkit-scrollbar-thumb:hover { + background: var(--text-secondary); + } + .option { width: 100%; - padding: 10px 16px; + height: 40px; + padding: 0 16px; + display: flex; + align-items: center; text-align: left; font-size: 13px; color: var(--text-secondary); @@ -213,10 +405,13 @@ cursor: pointer; transition: background-color 150ms ease, color 150ms ease; white-space: nowrap; + scroll-snap-align: start; + flex-shrink: 0; } .menu.compact .option { - padding: 8px 12px; + height: 36px; + padding: 0 12px; font-size: 12px; } @@ -235,4 +430,11 @@ background-color: rgba(var(--accent-primary), 0.15); color: var(--accent-primary); } + + .no-results { + padding: 12px 16px; + text-align: center; + color: var(--text-muted); + font-size: 13px; + }