Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): stop score level pills from squeezing out the option label (#18105)

Der Gerät0922c4cbaa40
diff --git a/web/src/components/design-system/SelectInput/SelectInput.stories.tsx b/web/src/components/design-system/SelectInput/SelectInput.stories.tsx
index 4ee6bf6dfa..104a360861 100644
--- a/web/src/components/design-system/SelectInput/SelectInput.stories.tsx
+++ b/web/src/components/design-system/SelectInput/SelectInput.stories.tsx
@@ -243,3 +243,106 @@ export const TestForwardsTriggerProps = meta.story({
await expect(body.getByRole("option", { name: "GPT-4.1" })).toHaveFocus();
},
});
+
+export const TestKeepsBadgedLabelReadable = meta.story({
+ name: "(Test) Keeps Badged Label Readable",
+ args: {
+ // The geometry the score-key picker actually ships in: a filter-sidebar
+ // width popover, a score name long enough to matter, and both level pills
+ // because one name can be scored at trace *and* observation level.
+ value: "answer_relevancy",
+ placeholder: "Select a key",
+ search: { placeholder: "Search keys..." },
+ options: [
+ {
+ value: "answer_relevancy",
+ label: "answer_relevancy",
+ badges: [
+ { text: "Trace", color: "violet" },
+ { text: "Observation", color: "blue" },
+ ],
+ },
+ ],
+ onValueChange: fn(),
+ },
+ render: (args) => (
+ <div className="w-50">
+ <SelectInput {...args} />
+ </div>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(canvas.getByRole("combobox"));
+
+ const option = await body.findByRole("option", {
+ name: /answer_relevancy/,
+ });
+ // The pills wrap beneath the name rather than squeezing it, so the name is
+ // laid out at its full width instead of being cut down to a few
+ // characters and an ellipsis.
+ const label = within(option).getByTitle("answer_relevancy");
+ await waitFor(() => {
+ // `scrollWidth <= clientWidth` alone is also satisfied by 0 <= 0, which
+ // is the collapsed state being guarded against — so pin the width too.
+ expect(label.clientWidth).toBeGreaterThan(0);
+ expect(label.scrollWidth).toBeLessThanOrEqual(label.clientWidth + 1);
+ // The pills survive the wrap intact — the name must not be won back by
+ // dropping the level information, nor by crushing the pills instead.
+ // Visibility alone would not catch that: Badge clips its own text with
+ // an ellipsis, so a squeezed "Observation" still renders a visible "O…".
+ for (const level of ["Trace", "Observation"]) {
+ const pill = within(option).getByText(level);
+ expect(pill).toBeVisible();
+ expect(pill.scrollWidth).toBeLessThanOrEqual(pill.clientWidth + 1);
+ }
+ });
+ },
+});
+
+export const TestKeepsBadgedLabelReadableWithoutSearch = meta.story({
+ name: "(Test) Keeps Badged Label Readable Without Search",
+ args: {
+ // Same case as above through the plain SelectPrimitive branch, which takes
+ // a different code path for badges and was otherwise untested.
+ value: "answer_relevancy",
+ placeholder: "Select a key",
+ options: [
+ {
+ value: "answer_relevancy",
+ label: "answer_relevancy",
+ badges: [
+ { text: "Trace", color: "violet" },
+ { text: "Observation", color: "blue" },
+ ],
+ },
+ ],
+ onValueChange: fn(),
+ },
+ render: (args) => (
+ <div className="w-50">
+ <SelectInput {...args} />
+ </div>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(canvas.getByRole("combobox"));
+
+ const option = await body.findByRole("option", {
+ name: /answer_relevancy/,
+ });
+ const label = within(option).getByTitle("answer_relevancy");
+ await waitFor(() => {
+ expect(label.clientWidth).toBeGreaterThan(0);
+ expect(label.scrollWidth).toBeLessThanOrEqual(label.clientWidth + 1);
+ for (const level of ["Trace", "Observation"]) {
+ const pill = within(option).getByText(level);
+ expect(pill).toBeVisible();
+ expect(pill.scrollWidth).toBeLessThanOrEqual(pill.clientWidth + 1);
+ }
+ });
+ },
+});
diff --git a/web/src/components/design-system/SelectInput/SelectInput.tsx b/web/src/components/design-system/SelectInput/SelectInput.tsx
index 7f3e7d9605..8ca071bede 100644
--- a/web/src/components/design-system/SelectInput/SelectInput.tsx
+++ b/web/src/components/design-system/SelectInput/SelectInput.tsx
@@ -155,10 +155,10 @@ function SelectInputInner<V extends string>(
? option.disabledReason
: option.label
}
+ badges={option.badges?.map((badge, index) => (
+ <Badge key={index} {...badge} />
+ ))}
/>
- {option.badges?.map((badge, index) => (
- <Badge key={index} {...badge} />
- ))}
</CommandPrimitive.Item>
</InputDropdown.Option>
));
@@ -226,10 +226,10 @@ function SelectInputInner<V extends string>(
</SelectPrimitive.ItemText>
}
title={node.disabled ? node.disabledReason : node.label}
+ badges={node.badges?.map((badge, index) => (
+ <Badge key={index} {...badge} />
+ ))}
/>
- {node.badges?.map((badge, index) => (
- <Badge key={index} {...badge} />
- ))}
</SelectPrimitive.SelectItem>
</InputDropdown.Option>
</React.Fragment>
diff --git a/web/src/components/design-system/internal/InputDropdown/InputDropdown.tsx b/web/src/components/design-system/internal/InputDropdown/InputDropdown.tsx
index 43e82e26cf..e29c57ac18 100644
--- a/web/src/components/design-system/internal/InputDropdown/InputDropdown.tsx
+++ b/web/src/components/design-system/internal/InputDropdown/InputDropdown.tsx
@@ -105,12 +105,19 @@ function Option({
function OptionContent({
label,
secondaryLabel,
+ badges,
title,
type,
checked,
}: {
label: ReactNode;
secondaryLabel?: string;
+ /**
+ * Trailing metadata pills. They share the label's line while it fits and wrap
+ * beneath it when it does not, so the label — the thing the option is picked
+ * by — is never the only item that can give up space.
+ */
+ badges?: ReactNode;
title: string;
type: "checkbox" | "checkmark" | "radio";
checked: boolean;
@@ -141,15 +148,31 @@ function OptionContent({
return (
<>
- <span className="min-w-0 flex-1 truncate" title={title}>
- {label}
- {secondaryLabel && (
- <span className="text-muted-foreground ml-1">{secondaryLabel}</span>
- )}
+ <span className="flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1">
+ {/*
+ `flex-auto`, not `flex-1`: the basis must stay `auto` so the label's
+ own width is what decides whether the badges still fit on this line
+ (a `flex-1` basis of 0 would let everything share one line forever,
+ which is the bug). Growing from that basis keeps the label filling
+ the row when it does fit, which is what holds the badges against the
+ right edge and keeps `title` hoverable across the whole row.
+ */}
+ <span className="flex-auto truncate" title={title}>
+ {label}
+ {secondaryLabel && (
+ <span className="text-muted-foreground ml-1">{secondaryLabel}</span>
+ )}
+ </span>
+ {badges}
</span>
<span
className={cn(
- "pointer-events-none flex size-3.5 shrink-0 items-center justify-center",
+ "pointer-events-none flex w-3.5 shrink-0 items-center justify-center",
+ // A badged row can wrap to two or three lines. Centring the indicator
+ // against the whole block would float it down level with the badges,
+ // away from the label it marks — so pin it to the first line's box
+ // (h-5 matches the row's text-sm line height) instead.
+ badges ? "h-5 self-start" : "h-3.5",
(type === "checkbox" || type === "radio") && "order-first",
)}
>