Skip to content

Commit eb659b0

Browse files
webui: simplify model search style and code
1 parent dae2759 commit eb659b0

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

tools/server/webui/src/lib/components/app/models/ModelsSelector.svelte

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
import { ServerModelStatus } from '$lib/enums';
1919
import { isRouterMode } from '$lib/stores/server.svelte';
2020
import { DialogModelInformation } from '$lib/components/app';
21-
import {
22-
MENU_MAX_WIDTH,
23-
MENU_OFFSET,
24-
VIEWPORT_GUTTER
25-
} from '$lib/constants/floating-ui-constraints';
21+
import { MENU_OFFSET, VIEWPORT_GUTTER } from '$lib/constants/floating-ui-constraints';
2622
import type { ModelOption } from '$lib/types/models';
2723
2824
interface Props {
@@ -256,7 +252,7 @@
256252
}
257253
}
258254
259-
function updateMenuPosition() {
255+
async function updateMenuPosition() {
260256
if (!isOpen || !triggerButton || !menuRef) return;
261257
262258
const triggerRect = triggerButton.getBoundingClientRect();
@@ -268,26 +264,16 @@
268264
const scrollHeight = menuRef.scrollHeight;
269265
270266
const availableWidth = Math.max(0, viewportWidth - VIEWPORT_GUTTER * 2);
271-
const safeMaxWidth = availableWidth > 0 ? availableWidth : MENU_MAX_WIDTH;
272-
const desiredMinWidth = Math.min(160, safeMaxWidth || 160);
267+
const safeMaxWidth = availableWidth || viewportWidth;
273268
274269
if (menuWidth === null) {
275270
menuRef.style.width = '';
276271
menuRef.style.maxWidth = '';
277272
278-
const idealWidth = Math.max(
279-
triggerRect.width,
280-
Math.min(menuRef.scrollWidth, safeMaxWidth),
281-
400
282-
);
283-
284-
menuWidth = Math.min(Math.max(idealWidth, desiredMinWidth), safeMaxWidth);
285-
} else if (safeMaxWidth && menuWidth > safeMaxWidth) {
286-
menuWidth = safeMaxWidth;
273+
const idealWidth = Math.max(triggerRect.width, Math.min(menuRef.scrollWidth, safeMaxWidth));
274+
menuWidth = Math.min(idealWidth, safeMaxWidth);
287275
}
288276
289-
const width = menuWidth ?? desiredMinWidth;
290-
291277
const availableBelow = Math.max(
292278
0,
293279
viewportHeight - VIEWPORT_GUTTER - triggerRect.bottom - MENU_OFFSET
@@ -337,14 +323,14 @@
337323
338324
const availableRight = viewportWidth - VIEWPORT_GUTTER;
339325
const rightAligned = Math.min(triggerRect.right, availableRight);
340-
let left = rightAligned - width;
341-
const maxLeft = viewportWidth - VIEWPORT_GUTTER - width;
326+
let left = rightAligned - menuWidth;
327+
const maxLeft = viewportWidth - VIEWPORT_GUTTER - menuWidth;
342328
left = Math.min(Math.max(left, VIEWPORT_GUTTER), Math.max(maxLeft, VIEWPORT_GUTTER));
343329
344330
menuPosition = {
345331
top: Math.round(metrics.top),
346332
left: Math.round(left),
347-
width: Math.round(width),
333+
width: Math.round(menuWidth),
348334
placement: metrics.placement,
349335
maxHeight: Math.round(metrics.maxHeight)
350336
};
@@ -491,11 +477,11 @@
491477
style:width={menuPosition ? `${menuPosition.width}px` : undefined}
492478
data-placement={menuPosition?.placement ?? 'bottom'}
493479
>
494-
<div class="border-b bg-popover px-3 py-2">
480+
<div class="px-3 py-2">
495481
<label class="sr-only" for="model-search">Search models</label>
496482
<input
497483
id="model-search"
498-
class="h-9 w-full rounded-md border border-input bg-background px-3 text-sm shadow-sm transition focus:border-ring focus:outline-none"
484+
class="h-9 w-full rounded-lg bg-muted px-3 text-sm outline-none placeholder:text-muted-foreground"
499485
placeholder="Search models"
500486
bind:value={searchTerm}
501487
bind:this={searchInputRef}
@@ -504,7 +490,6 @@
504490
type="search"
505491
/>
506492
</div>
507-
508493
<div
509494
class="overflow-y-auto py-1"
510495
style:max-height={menuPosition && menuPosition.maxHeight > 0
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export const VIEWPORT_GUTTER = 8;
22
export const MENU_OFFSET = 6;
3-
export const MENU_MAX_WIDTH = 320;

0 commit comments

Comments
 (0)