diff --git a/SharpbinV3.Client/src/lib/components/Dropdown.svelte b/SharpbinV3.Client/src/lib/components/Dropdown.svelte index f74b882..bf8a8eb 100644 --- a/SharpbinV3.Client/src/lib/components/Dropdown.svelte +++ b/SharpbinV3.Client/src/lib/components/Dropdown.svelte @@ -16,6 +16,8 @@ let isOpen = false; let searchQuery = ''; let dropdownElement: HTMLDivElement; + let dropdownListElement: HTMLDivElement; + let dropdownMaxHeight = '12rem'; $: filteredOptions = searchable ? options.filter( @@ -39,10 +41,18 @@ function toggleDropdown() { isOpen = !isOpen; - if (isOpen && searchable) { + if (isOpen) { setTimeout(() => { - const input = dropdownElement?.querySelector('input[type="text"]') as HTMLInputElement; - input?.focus(); + if (dropdownElement && dropdownListElement) { + const rect = dropdownElement.getBoundingClientRect(); + const spaceBelow = window.innerHeight - rect.bottom - 8; + const maxCap = 416; + dropdownMaxHeight = Math.max(120, Math.min(spaceBelow, maxCap)) + 'px'; + } + if (searchable) { + const input = dropdownElement?.querySelector('input[type="text"]') as HTMLInputElement; + input?.focus(); + } }, 0); } } @@ -56,7 +66,7 @@ -
+