Skip to content

Commit 9681897

Browse files
authored
WebUI: Replace illegal nested button elements (#21026)
* remove/replace nested button elements * map rest props to outer element * solve TODO * chore: update webui build output
1 parent e397d38 commit 9681897

3 files changed

Lines changed: 55 additions & 47 deletions

File tree

tools/server/public/index.html.gz

172 Bytes
Binary file not shown.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
showRaw = undefined,
1919
aliases,
2020
tags,
21-
class: className = ''
21+
class: className = '',
22+
...rest
2223
}: Props = $props();
2324
2425
const badgeClass =
@@ -36,9 +37,9 @@
3637
</script>
3738

3839
{#if resolvedShowRaw}
39-
<TruncatedText class="font-medium {className}" showTooltip={false} text={modelId} />
40+
<TruncatedText class="font-medium {className}" showTooltip={false} text={modelId} {...rest} />
4041
{:else}
41-
<span class="flex min-w-0 flex-wrap items-center gap-1 {className}">
42+
<span class="flex min-w-0 flex-wrap items-center gap-1 {className}" {...rest}>
4243
<span class="min-w-0 truncate font-medium">
4344
{#if showOrgName && parsed.orgName && !(aliases && aliases.length > 0)}{parsed.orgName}/{/if}{displayName}
4445
</span>

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

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -271,50 +271,49 @@
271271
{#if isRouter}
272272
<DropdownMenu.Root bind:open={isOpen} onOpenChange={handleOpenChange}>
273273
<DropdownMenu.Trigger
274+
class={cn(
275+
`inline-grid cursor-pointer grid-cols-[1fr_auto_1fr] items-center gap-1.5 rounded-sm bg-muted-foreground/10 px-1.5 py-1 text-xs transition hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60`,
276+
!isCurrentModelInCache
277+
? 'bg-red-400/10 !text-red-400 hover:bg-red-400/20 hover:text-red-400'
278+
: forceForegroundText
279+
? 'text-foreground'
280+
: isHighlightedCurrentModelActive
281+
? 'text-foreground'
282+
: 'text-muted-foreground',
283+
isOpen ? 'text-foreground' : ''
284+
)}
285+
style="max-width: min(calc(100cqw - 9rem), 20rem)"
274286
disabled={disabled || updating}
275-
onclick={(e) => {
276-
e.preventDefault();
277-
e.stopPropagation();
278-
}}
279287
>
280-
<button
281-
type="button"
282-
class={cn(
283-
`inline-grid cursor-pointer grid-cols-[1fr_auto_1fr] items-center gap-1.5 rounded-sm bg-muted-foreground/10 px-1.5 py-1 text-xs transition hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60`,
284-
!isCurrentModelInCache
285-
? 'bg-red-400/10 !text-red-400 hover:bg-red-400/20 hover:text-red-400'
286-
: forceForegroundText
287-
? 'text-foreground'
288-
: isHighlightedCurrentModelActive
289-
? 'text-foreground'
290-
: 'text-muted-foreground',
291-
isOpen ? 'text-foreground' : ''
292-
)}
293-
style="max-width: min(calc(100cqw - 9rem), 20rem)"
294-
disabled={disabled || updating}
295-
>
296-
<Package class="h-3.5 w-3.5" />
297-
298-
{#if selectedOption}
299-
<Tooltip.Root>
300-
<Tooltip.Trigger class="min-w-0 overflow-hidden">
301-
<ModelId modelId={selectedOption.model} class="min-w-0" showOrgName />
302-
</Tooltip.Trigger>
303-
304-
<Tooltip.Content>
305-
<p class="font-mono">{selectedOption.model}</p>
306-
</Tooltip.Content>
307-
</Tooltip.Root>
308-
{:else}
309-
<span class="min-w-0 font-medium">Select model</span>
310-
{/if}
311-
312-
{#if updating || isLoadingModel}
313-
<Loader2 class="h-3 w-3.5 animate-spin" />
314-
{:else}
315-
<ChevronDown class="h-3 w-3.5" />
316-
{/if}
317-
</button>
288+
<Package class="h-3.5 w-3.5" />
289+
290+
{#if selectedOption}
291+
<Tooltip.Root>
292+
<Tooltip.Trigger>
293+
<!-- prevent another nested button element -->
294+
{#snippet child({ props })}
295+
<ModelId
296+
modelId={selectedOption.model}
297+
class="min-w-0 overflow-hidden"
298+
showOrgName
299+
{...props}
300+
/>
301+
{/snippet}
302+
</Tooltip.Trigger>
303+
304+
<Tooltip.Content>
305+
<p class="font-mono">{selectedOption.model}</p>
306+
</Tooltip.Content>
307+
</Tooltip.Root>
308+
{:else}
309+
<span class="min-w-0 font-medium">Select model</span>
310+
{/if}
311+
312+
{#if updating || isLoadingModel}
313+
<Loader2 class="h-3 w-3.5 animate-spin" />
314+
{:else}
315+
<ChevronDown class="h-3 w-3.5" />
316+
{/if}
318317
</DropdownMenu.Trigger>
319318

320319
<DropdownMenu.Content
@@ -407,8 +406,16 @@
407406

408407
{#if selectedOption}
409408
<Tooltip.Root>
410-
<Tooltip.Trigger class="min-w-0 overflow-hidden">
411-
<ModelId modelId={selectedOption.model} class="min-w-0" showOrgName />
409+
<Tooltip.Trigger>
410+
<!-- prevent another nested button element -->
411+
{#snippet child({ props })}
412+
<ModelId
413+
modelId={selectedOption.model}
414+
class="min-w-0 overflow-hidden"
415+
showOrgName
416+
{...props}
417+
/>
418+
{/snippet}
412419
</Tooltip.Trigger>
413420

414421
<Tooltip.Content>

0 commit comments

Comments
 (0)