Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions apps/web/src/components/chat/ModelListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ComboboxItem } from "../ui/combobox";
import { Button } from "../ui/button";
import { Badge } from "../ui/badge";
import { Kbd } from "../ui/kbd";
import { MiddleTruncate } from "../ui/middle-truncate";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { cn } from "~/lib/utils";
import { modelPickerModelKey } from "./modelPickerKeys";
Expand Down Expand Up @@ -36,11 +37,14 @@ export const ModelListRow = memo(function ModelListRow(props: {
onToggleFavorite: (instanceId: ProviderInstanceId, slug: string) => void;
}) {
const gt = useGT();
const model = {
const displayName = getDisplayModelName({
slug: props.slug,
name: props.name,
subProvider: props.subProvider,
};
});
const lastSlash = displayName.lastIndexOf("/");
// The slash stays in the head: MiddleTruncate needs 5+ head characters to split, so "meta/" must count.
const pathTail = lastSlash > 0 ? Array.from(displayName.slice(lastSlash + 1)).length : undefined;

const row = (
<ComboboxItem
Expand Down Expand Up @@ -69,17 +73,27 @@ export const ModelListRow = memo(function ModelListRow(props: {
badgeClassName="right-[-0.125rem] bottom-[-0.125rem] h-3 min-w-3 px-0.5 text-5xs"
/>
<div className="flex min-w-0 flex-1 items-center gap-2 text-left">
<div
className="min-w-0 truncate text-sm font-normal leading-snug"
// Names the row in full on hover only when it is cut off.
onPointerEnter={(event) => {
const name = event.currentTarget;
name.title = name.scrollWidth > name.clientWidth ? getDisplayModelName(model) : "";
}}
>
{getDisplayModelName(model)}
<div className="flex min-w-0 text-sm font-normal leading-snug">
{/* Custom models often share a long path, so the cut takes the path and keeps the model
name whole. Its "…" would be read aloud, so screen readers get the sr-only name below. */}
<MiddleTruncate
value={displayName}
{...(pathTail === undefined ? {} : { tail: pathTail })}
Comment thread
Muzammil-Bit marked this conversation as resolved.
Resolved
showTitle={false}
aria-hidden="true"
// Names the row in full on hover only when it is cut off.
onPointerEnter={(event) => {
const name = event.currentTarget;
const isCut = Array.from(name.children).some(
(part) => part.scrollWidth > part.clientWidth,
);
name.title = isCut ? displayName : "";
}}
/>
{/* The logo is decorative, so name the provider for screen readers. */}
<span className="sr-only">, {props.providerDisplayName}</span>
<span className="sr-only">
{displayName}, {props.providerDisplayName}
</span>
</div>
{props.isSelected ? <CheckIcon className="size-3.5 shrink-0" aria-hidden="true" /> : null}
{props.subProvider ? (
Expand Down
16 changes: 16 additions & 0 deletions apps/web/src/components/ui/middle-truncate.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ describe("MiddleTruncate", () => {
);
});

it("keeps a tail wider than the box inside it", async () => {
const value = "organization/qwen3-coder-480b-a35b-instruct-turbo";
await using screen = await render(
<div style={{ width: 80 }}>
<MiddleTruncate value={value} tail={value.length - 12} className="w-full" />
</div>,
);
const box = screen.container.querySelector<HTMLElement>("[title]")!;
const tail = box.querySelector<HTMLElement>("span:last-child")!;

expect(tail.getBoundingClientRect().right).toBeLessThanOrEqual(
box.getBoundingClientRect().right,
);
expect(tail.scrollWidth).toBeGreaterThan(tail.clientWidth);
});

it.each([
["Fix the sidebar", 7],
["report\u2003\u2003draft.txt", 9],
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/ui/middle-truncate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export function MiddleTruncate({
<span ref={headRef} className="peer min-w-0 overflow-hidden whitespace-pre">
{split.head}
</span>
<span className="shrink-0 whitespace-pre peer-data-overflow:before:content-['…']">
{/* A tail wider than the box ends in its own ellipsis instead of spilling out. */}
<span className="max-w-full shrink-0 overflow-hidden text-ellipsis whitespace-pre peer-data-overflow:before:content-['…']">
{split.tail}
</span>
</>
Expand Down
Loading