🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): Create `SelectInput` & fix `SupportForm` issues (#17037)
Ben Bachem5b1cbc34c1ac
diff --git a/web/src/components/design-system/SelectInput/SelectInput.stories.tsx b/web/src/components/design-system/SelectInput/SelectInput.stories.tsxnew file mode 100644index 0000000000..b7534ab36f--- /dev/null+++ b/web/src/components/design-system/SelectInput/SelectInput.stories.tsx@@ -0,0 +1,162 @@+import { useState } from "react";+import { expect, fn, userEvent, within } from "storybook/test";+import preview from "../../../../.storybook/preview";+import { SelectInput } from "./SelectInput";++const meta = preview.meta({+ component: SelectInput,+});++export const Default = meta.story({+ args: {+ value: "gpt-4.1",+ placeholder: "Select a model",+ options: [+ {+ type: "group",+ id: "openai",+ label: "OpenAI",+ options: [+ { value: "gpt-4.1", label: "GPT-4.1" },+ { value: "gpt-4.1-mini", label: "GPT-4.1 mini" },+ { value: "gpt-4.1-nano", label: "GPT-4.1 nano" },+ { value: "o3", label: "o3" },+ ],+ },+ {+ type: "group",+ id: "anthropic",+ label: "Anthropic",+ options: [+ {+ value: "claude-opus-4",+ label: "Claude Opus 4",+ disabled: true,+ disabledReason: "Claude Opus 4 is not available for this project.",+ },+ { value: "claude-sonnet-4", label: "Claude Sonnet 4" },+ { value: "claude-haiku-3.5", label: "Claude Haiku 3.5" },+ { value: "claude-3.7-sonnet", label: "Claude 3.7 Sonnet" },+ ],+ },+ {+ type: "group",+ id: "google",+ label: "Google",+ options: [+ { value: "gemini-2.5-pro", label: "Gemini 2.5 Pro" },+ { value: "gemini-2.5-flash", label: "Gemini 2.5 Flash" },+ { value: "gemini-2.0-flash", label: "Gemini 2.0 Flash" },+ { value: "gemini-1.5-pro", label: "Gemini 1.5 Pro" },+ ],+ },+ ],+ onValueChange: fn(),+ },+ render: (args) => {+ const [value, setValue] = useState(args.value);++ return (+ <SelectInput+ {...args}+ value={value}+ onValueChange={(newValue) => {+ setValue(newValue);+ args.onValueChange(newValue);+ }}+ />+ );+ },+});++export const TestKeyboardSelection = meta.story({+ name: "(Test) Keyboard Selection",+ args: {+ value: "gpt-4.1",+ placeholder: "Select a model",+ options: [+ { value: "gpt-4.1", label: "GPT-4.1" },+ { value: "gpt-4.1-mini", label: "GPT-4.1 mini" },+ ],+ onValueChange: fn(),+ },+ play: async ({ args, canvasElement }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ const trigger = canvas.getByRole("combobox");++ await userEvent.click(trigger);++ const firstOption = body.getByRole("option", { name: "GPT-4.1" });+ const secondOption = body.getByRole("option", {+ name: "GPT-4.1 mini",+ });+ await expect(firstOption).toHaveFocus();++ await userEvent.keyboard("{ArrowDown}");+ await expect(secondOption).toHaveFocus();++ await userEvent.keyboard("{ArrowUp}");+ await expect(firstOption).toHaveFocus();++ await userEvent.keyboard("{ArrowDown}{Enter}");+ await expect(args.onValueChange).toHaveBeenCalledWith("gpt-4.1-mini");+ },+});++export const TestSkipsDisabledOption = meta.story({+ name: "(Test) Skips Disabled Option",+ args: {+ value: "gpt-4.1",+ placeholder: "Select a model",+ options: [+ { value: "gpt-4.1", label: "GPT-4.1" },+ {+ value: "gpt-4.1-mini",+ label: "GPT-4.1 mini",+ disabled: true,+ disabledReason: "GPT-4.1 mini is not available for this project.",+ },+ { value: "gpt-4.1-nano", label: "GPT-4.1 nano" },+ ],+ onValueChange: fn(),+ },+ play: async ({ args, canvasElement }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);++ await userEvent.click(canvas.getByRole("combobox"));+ await userEvent.keyboard("{ArrowDown}");++ const enabledOption = body.getByRole("option", { name: "GPT-4.1 nano" });+ await expect(enabledOption).toHaveFocus();++ await userEvent.keyboard("{Enter}");+ await expect(args.onValueChange).toHaveBeenCalledWith("gpt-4.1-nano");+ },+});++export const TestForwardsTriggerProps = meta.story({+ name: "(Test) Forwards Trigger Props",+ args: {+ value: "gpt-4.1",+ placeholder: "Select a model",+ options: [{ value: "gpt-4.1", label: "GPT-4.1" }],+ onValueChange: fn(),+ },+ render: (args) => (+ <>+ <label htmlFor="model-select">Model</label>+ <SelectInput {...args} id="model-select" />+ </>+ ),+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ const trigger = canvas.getByRole("combobox");++ await expect(trigger).toHaveAttribute("id", "model-select");+ await userEvent.click(canvas.getByText("Model"));+ await expect(body.getByRole("option", { name: "GPT-4.1" })).toHaveFocus();+ },+});diff --git a/web/src/components/design-system/SelectInput/SelectInput.tsx b/web/src/components/design-system/SelectInput/SelectInput.tsxnew file mode 100644index 0000000000..41c7b68935--- /dev/null+++ b/web/src/components/design-system/SelectInput/SelectInput.tsx@@ -0,0 +1,200 @@+/* eslint-disable boundaries/dependencies */+"use client";++import * as React from "react";+import * as SelectPrimitive from "@radix-ui/react-select";++import { assertUnreachable } from "@langfuse/shared";+import { useCallback } from "react";+import { useLayerContainer } from "../../ui/layer";+import { Check, ChevronDown, ChevronUp } from "lucide-react";+import { cn } from "@/src/utils/tailwind";+import { useScrollGradients } from "@/src/hooks/useScrollGradients";+import {+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from "@/src/components/ui/tooltip";++type SelectOption<V> =+ | {+ value: V;+ label: string;+ disabled?: false;+ disabledReason?: never;+ }+ | {+ value: V;+ label: string;+ disabled: true;+ disabledReason: string;+ };++type SelectGroup<V> = {+ type: "group";+ id: string;+ label: string;+ options: SelectOption<V>[];+};++type SelectInputNode<V> = SelectOption<V> | SelectGroup<V>;++type SelectInputProps<V> = {+ value: V;+ options: SelectInputNode<V>[];+ onValueChange: (newValue: V) => void;+ placeholder: string;+} & Pick<+ React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>,+ "id" | "aria-describedby" | "aria-invalid"+>;++function isSelectGroup<V>(node: SelectInputNode<V>): node is SelectGroup<V> {+ return "type" in node && node.type === "group";+}++function SelectInputInner<V extends string>(+ {+ value,+ options,+ onValueChange,+ placeholder,+ ...triggerProps+ }: SelectInputProps<V>,+ ref: React.ForwardedRef<HTMLButtonElement>,+) {+ const container = useLayerContainer("popover");+ const [open, setOpen] = React.useState(false);+ const { register, recompute, top, bottom } =+ useScrollGradients<React.ComponentRef<typeof SelectPrimitive.Viewport>>(+ true,+ );+ const renderNode = useCallback(+ (+ node: SelectInputNode<V>,+ hasPreviousGroup: boolean,+ ): React.ReactElement => {+ if (isSelectGroup(node)) {+ return (+ <React.Fragment key={node.id}>+ {hasPreviousGroup && (+ <SelectPrimitive.Separator className="bg-border my-2 h-px" />+ )}+ <SelectPrimitive.Group>+ <SelectPrimitive.Label className="text-muted-foreground px-1 py-1.5 text-xs font-bold">+ {node.label}+ </SelectPrimitive.Label>+ {node.options.map((option) => renderNode(option, false))}+ </SelectPrimitive.Group>+ </React.Fragment>+ );+ }++ if ("value" in node) {+ const option = (+ <SelectPrimitive.SelectItem+ key={node.value}+ value={node.value}+ disabled={node.disabled}+ className={cn(+ "focus:bg-accent focus:text-accent-foreground relative flex w-full cursor-default items-center rounded-sm px-1.5 py-1.5 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50",+ hasPreviousGroup ? "mt-4" : "",+ )}+ >+ <SelectPrimitive.ItemText>{node.label}</SelectPrimitive.ItemText>+ <SelectPrimitive.ItemIndicator className="ml-auto flex size-3.5 shrink-0 items-center justify-center">+ <Check className="size-4" />+ </SelectPrimitive.ItemIndicator>+ </SelectPrimitive.SelectItem>+ );++ if (!node.disabled) {+ return option;+ }++ return (+ // disableHoverableContent keeps the tooltip grace area from swallowing hover between adjacent disabled options.+ <Tooltip key={node.value} disableHoverableContent>+ <TooltipTrigger asChild>+ {/* Disabled items ignore pointer events, so this wrapper owns the tooltip trigger. */}+ <div>{option}</div>+ </TooltipTrigger>+ <TooltipContent className="max-w-xs">+ {node.disabledReason}+ </TooltipContent>+ </Tooltip>+ );+ }++ return assertUnreachable(node);+ },+ [],+ );++ return (+ <SelectPrimitive.Root+ value={value}+ onValueChange={onValueChange}+ open={open}+ onOpenChange={setOpen}+ >+ <SelectPrimitive.Trigger+ ref={ref}+ className="border-input bg-background ring-offset-background placeholder:text-foreground-tertiary focus:ring-ring disabled:bg-muted/50 flex h-8 w-full items-center justify-between gap-1 rounded-md border px-3 py-2 text-sm focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:cursor-not-allowed disabled:opacity-50"+ {...triggerProps}+ >+ <SelectPrimitive.SelectValue placeholder={placeholder} />+ <SelectPrimitive.Icon asChild>+ <ChevronDown className="h-4 w-4 opacity-50" />+ </SelectPrimitive.Icon>+ </SelectPrimitive.Trigger>+ <SelectPrimitive.Portal container={container}>+ <SelectPrimitive.Content+ position="popper"+ sideOffset={4}+ className="bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative w-(--radix-select-trigger-width) min-w-32 overflow-hidden rounded-md border shadow-md"+ >+ <SelectPrimitive.ScrollUpButton+ aria-label="Scroll up"+ className="animate-in fade-in-0 fill-mode-both absolute inset-x-0 top-0 z-3 flex h-6 items-center justify-center duration-300 [animation-delay:.5s]"+ >+ <ChevronUp className="size-4" />+ </SelectPrimitive.ScrollUpButton>+ <SelectPrimitive.Viewport+ ref={register}+ onScroll={recompute}+ className={cn(+ "before:from-popover after:from-popover max-h-96 overflow-auto p-1.5 before:pointer-events-none before:sticky before:top-0 before:z-2 before:-mx-1.5 before:-mb-6 before:block before:h-6 before:bg-linear-to-b before:to-transparent before:content-[''] after:pointer-events-none after:sticky after:bottom-0 after:z-2 after:-mx-1.5 after:-mt-6 after:block after:h-6 after:bg-linear-to-t after:to-transparent after:content-['']",+ top ? "before:opacity-100" : "before:opacity-0",+ bottom ? "after:opacity-100" : "after:opacity-0",+ )}+ >+ {options.map((node, index) =>+ renderNode(node, index > 0 && isSelectGroup(options[index - 1])),+ )}+ </SelectPrimitive.Viewport>+ <SelectPrimitive.ScrollDownButton+ aria-label="Scroll down"+ className="animate-in fade-in-0 fill-mode-both absolute inset-x-0 bottom-0 z-3 flex h-6 items-center justify-center duration-300 [animation-delay:.5s]"+ >+ <ChevronDown className="size-4" />+ </SelectPrimitive.ScrollDownButton>+ </SelectPrimitive.Content>+ </SelectPrimitive.Portal>+ </SelectPrimitive.Root>+ );+}++type SelectInputComponent = {+ <V extends string>(+ props: SelectInputProps<V> & React.RefAttributes<HTMLButtonElement>,+ ): React.ReactElement | null;++ displayName?: string;+};++export const SelectInput = React.forwardRef(+ SelectInputInner,+) as SelectInputComponent;++SelectInput.displayName = "SelectInput";diff --git a/web/src/components/ui/dropdown-menu.tsx b/web/src/components/ui/dropdown-menu.tsxindex 3b64c2fa6a..17a0708b61 100644--- a/web/src/components/ui/dropdown-menu.tsx+++ b/web/src/components/ui/dropdown-menu.tsx@@ -137,20 +137,28 @@ const DropdownContentWrapper = React.forwardRef<const { register, recompute, top, bottom } = useScrollGradients<React.ComponentRef<typeof DropdownMenuPrimitive.Content>>(maxHeight !== undefined);+ const setContentRef = React.useCallback(+ (+ element: React.ComponentRef<+ typeof DropdownMenuPrimitive.Content+ > | null,+ ) => {+ register(element);+ if (typeof ref === "function") {+ ref(element);+ } else if (ref) {+ ref.current = element;+ }+ },+ [ref, register],+ );const content =typeof children === "function" ? children({ top, bottom }) : children;return (<DropdownMenuPrimitive.Portal container={container}><DropdownMenuPrimitive.Content- ref={(element) => {- register(element);- if (typeof ref === "function") {- ref(element);- } else if (ref) {- ref.current = element;- }- }}+ ref={setContentRef}sideOffset={sideOffset}className={cn(dropdownMenuContentVariants({diff --git a/web/src/features/support-chat/SupportForm.tsx b/web/src/features/support-chat/SupportForm.tsxindex a20d2cfd93..dcb1d7ac30 100644--- a/web/src/features/support-chat/SupportForm.tsx+++ b/web/src/features/support-chat/SupportForm.tsx@@ -38,18 +38,7 @@ import {AlertDialogHeader,AlertDialogTitle,} from "@/src/components/ui/alert-dialog";-import {- Tooltip,- TooltipContent,- TooltipTrigger,-} from "@/src/components/ui/tooltip";-import {- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,-} from "@/src/components/ui/select";+import { SelectInput } from "@/src/components/design-system/SelectInput/SelectInput";import { Textarea } from "@/src/components/ui/textarea";import { useEffect, useState } from "react";@@ -361,40 +350,28 @@ export function SupportForm({<FormItem><FormLabel>Priority</FormLabel><FormControl>- <Select value={field.value} onValueChange={field.onChange}>- <SelectTrigger>- <SelectValue placeholder="Select a priority" />- </SelectTrigger>- <SelectContent>- {SEVERITIES.map((s) =>- isSeveritySelectable(s, canSelectHighSeverity) ? (- <SelectItem key={s} value={s}>- {s}- </SelectItem>- ) : (- // disableHoverableContent: without it, the grace- // area between item and tooltip swallows the hover- // when moving between the two adjacent gated items.- <Tooltip key={s} disableHoverableContent>- {/* Disabled items are pointer-events-none, so the- wrapper div must catch the hover instead. */}- <TooltipTrigger asChild>- <div>- <SelectItem value={s} disabled>- {s}- </SelectItem>- </div>- </TooltipTrigger>- <TooltipContent className="max-w-xs">- {s === SEVERITY_1- ? "Severity 1 is available on the Enterprise plan."- : "Severity 2 is available on the Enterprise plan."}- </TooltipContent>- </Tooltip>- ),- )}- </SelectContent>- </Select>+ <SelectInput+ value={field.value}+ onValueChange={field.onChange}+ placeholder="Select a priority"+ options={SEVERITIES.map((severity) => {+ if (+ isSeveritySelectable(severity, canSelectHighSeverity)+ ) {+ return { value: severity, label: severity };+ }++ return {+ value: severity,+ label: severity,+ disabled: true as const,+ disabledReason:+ severity === SEVERITY_1+ ? "Severity 1 is available on the Enterprise plan."+ : "Severity 2 is available on the Enterprise plan.",+ };+ })}+ /></FormControl><FormMessage /></FormItem>@@ -409,36 +386,31 @@ export function SupportForm({<FormItem><FormLabel>Topic</FormLabel><FormControl>- <Select- value={(field.value as string | undefined) ?? undefined}+ <SelectInput+ value={field.value ?? undefined}onValueChange={field.onChange}- >- <SelectTrigger>- <SelectValue placeholder="Select a topic" />- </SelectTrigger>- <SelectContent>- <div className="p-2">- <div className="text-muted-foreground mb-2 text-xs font-bold">- Product Features- </div>- {productFeatureTopics.map((t) => (- <SelectItem key={t} value={t}>- {t}- </SelectItem>- ))}- </div>- <div className="border-t p-2">- <div className="text-muted-foreground mb-2 text-xs font-bold">- Operations- </div>- {TopicGroups.Operations.map((t) => (- <SelectItem key={t} value={t}>- {t}- </SelectItem>- ))}- </div>- </SelectContent>- </Select>+ placeholder="Select a topic"+ options={[+ {+ type: "group",+ id: "product-features",+ label: "Product Features",+ options: productFeatureTopics.map((t) => ({+ value: t,+ label: t,+ })),+ },+ {+ type: "group",+ id: "operations",+ label: "Operations",+ options: TopicGroups.Operations.map((t) => ({+ value: t,+ label: t,+ })),+ },+ ]}+ /></FormControl><FormMessage /></FormItem>@@ -454,18 +426,15 @@ export function SupportForm({<FormItem><FormLabel>Integration Type (optional)</FormLabel><FormControl>- <Select value={field.value} onValueChange={field.onChange}>- <SelectTrigger>- <SelectValue placeholder="Select integration type" />- </SelectTrigger>- <SelectContent>- {INTEGRATION_TYPES.map((it) => (- <SelectItem key={it} value={it}>- {it}- </SelectItem>- ))}- </SelectContent>- </Select>+ <SelectInput+ value={field.value ?? ""}+ onValueChange={field.onChange}+ placeholder="Select integration type"+ options={INTEGRATION_TYPES.map((integrationType) => ({+ value: integrationType,+ label: integrationType,+ }))}+ /></FormControl><FormMessage /></FormItem>diff --git a/web/src/hooks/useScrollGradients.clienttest.ts b/web/src/hooks/useScrollGradients.clienttest.tsnew file mode 100644index 0000000000..60adf834c5--- /dev/null+++ b/web/src/hooks/useScrollGradients.clienttest.ts@@ -0,0 +1,36 @@+import { act, renderHook } from "@testing-library/react";+import { afterEach, describe, expect, it, vi } from "vitest";++import { useScrollGradients } from "./useScrollGradients";++class Observer {+ observe() {}+ disconnect() {}+}++describe("useScrollGradients", () => {+ afterEach(() => {+ vi.unstubAllGlobals();+ });++ it("measures a viewport registered after mount", () => {+ vi.stubGlobal("ResizeObserver", Observer);+ vi.stubGlobal("MutationObserver", Observer);++ const { result } = renderHook(() =>+ useScrollGradients<HTMLDivElement>(true),+ );+ const viewport = document.createElement("div");+ Object.defineProperties(viewport, {+ clientHeight: { configurable: true, value: 100 },+ scrollHeight: { configurable: true, value: 200 },+ });++ act(() => {+ result.current.register(viewport);+ });++ expect(result.current.top).toBe(false);+ expect(result.current.bottom).toBe(true);+ });+});diff --git a/web/src/hooks/useScrollGradients.ts b/web/src/hooks/useScrollGradients.tsindex 49c9f01e00..7dd1029046 100644--- a/web/src/hooks/useScrollGradients.ts+++ b/web/src/hooks/useScrollGradients.ts@@ -1,4 +1,4 @@-import { useCallback, useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useState } from "react";const SCROLL_EDGE_THRESHOLD_PX = 10;@@ -10,16 +10,15 @@ const SCROLL_EDGE_THRESHOLD_PX = 10;export function useScrollGradients<TElement extends HTMLElement>(enabled: boolean,) {- const contentRef = useRef<TElement>(null);+ const [element, setElement] = useState<TElement | null>(null);const [{ top, bottom }, setScrollGradients] = useState({top: false,bottom: false,});const register = useCallback((element: TElement | null) => {- contentRef.current = element;+ setElement(element);}, []);const recompute = useCallback(() => {- const element = contentRef.current;if (!element || !enabled) return;const maxScrollTop = element.scrollHeight - element.clientHeight;@@ -36,10 +35,9 @@ export function useScrollGradients<TElement extends HTMLElement>(}return { top: nextTop, bottom: nextBottom };});- }, [enabled]);+ }, [element, enabled]);useEffect(() => {- const element = contentRef.current;if (!element || !enabled) return;const update = () => recompute();@@ -58,7 +56,7 @@ export function useScrollGradients<TElement extends HTMLElement>(resizeObserver.disconnect();mutationObserver.disconnect();};- }, [enabled, recompute]);+ }, [element, enabled, recompute]);return { register, recompute, top, bottom };}