fix: reposition the model selector dropdown when its content changes size after opening

This commit is contained in:
silentoplayz 2026-09-09 13:10:43 -04:00
parent 8383bc708c
commit 8b344aed15

View file

@ -209,6 +209,7 @@
updatePosition();
await tick();
updatePosition();
scheduleSettledPositionUpdates();
for (const delay of [0, 50, 150]) {
window.setTimeout(focusSearchInput, delay);
}
@ -960,6 +961,21 @@
};
};
const trackContentSize = (node: HTMLElement) => {
if (!('ResizeObserver' in window)) {
return { destroy() {} };
}
const observer = new ResizeObserver(schedulePositionUpdate);
observer.observe(node);
return {
destroy() {
observer.disconnect();
}
};
};
$: visibleStart = Math.max(0, Math.floor(listScrollTop / ITEM_HEIGHT) - OVERSCAN);
$: visibleEnd = Math.min(
filteredItems.length,
@ -1027,6 +1043,7 @@
>
<div
bind:this={panelElement}
use:trackContentSize
class="z-40 {className ??
'w-[20rem]'} max-w-[calc(100vw-1rem)] justify-start rounded-xl border border-gray-100 bg-white p-0.5 shadow-lg outline-hidden dark:border-gray-800 dark:bg-gray-850 dark:text-white flex flex-col overflow-hidden"
style={dropdownPosition.maxHeight ? `max-height: ${dropdownPosition.maxHeight}px;` : ''}