TypeScript
fix(web): question options show a radio and an aligned shortcut key (#23255)
mariad414cb51032f
diff --git a/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx b/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsxindex a17e67a6213..13d3d22aa88 100644--- a/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx+++ b/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx@@ -7,8 +7,9 @@ import {derivePendingUserInputProgress,type PendingUserInputDraftAnswer,} from "../../pendingUserInput";-import { CheckIcon } from "lucide-react";+import { CheckboxMark } from "../ui/checkbox";import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";+import { Kbd } from "../ui/kbd";import { cn } from "~/lib/utils";import { ComposerBanner } from "./ComposerBanner";import ChatMarkdown from "../ChatMarkdown";@@ -189,23 +190,24 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(isCollapsed ? "Show the question and its options" : "Hide the question and its options"}data-pending-user-input-toggle={isCollapsed ? "collapsed" : "expanded"}+ className="px-4 pt-1.5">- <ComposerBanner.Icon /><ComposerBanner.Content>- <span className="shrink-0 font-medium text-muted-foreground">- {activeQuestion.header}- </span>+ <span className="shrink-0 text-muted-foreground">{activeQuestion.header}</span>{isCollapsed ? (- <span className="min-w-0 flex-1 truncate text-secondary-label">- {activeQuestion.question}- </span>+ <>+ <ComposerBanner.Separator />+ <span className="min-w-0 flex-1 truncate text-secondary-label">+ {activeQuestion.question}+ </span>+ </>) : null}</ComposerBanner.Content>- <ComposerBanner.Actions>+ <ComposerBanner.Actions className="gap-0">{prompt.questions.length > 1 ? (- <span className="text-3xs font-medium text-muted-foreground tabular-nums">+ <ComposerBanner.Count>{questionIndex + 1}/{prompt.questions.length}- </span>+ </ComposerBanner.Count>) : null}<ComposerBanner.ToggleIcon expanded={!isCollapsed} />{prompt.dismissible ? (@@ -232,17 +234,15 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(</CollapsibleTrigger><CollapsiblePanel><ComposerBanner.Scroll>- <ComposerBanner.Body className="pe-1 pb-1 wrap-anywhere">+ <ComposerBanner.Body className="ps-6 pe-4 pb-1 wrap-anywhere sm:ps-5.5"><ChatMarkdowntext={activeQuestion.question}cwd={cwd}threadRef={threadRef}- className="text-foreground/85"+ className="pt-2 text-foreground/85"/>- {activeQuestion.multiSelect ? (- <p className="mt-1 text-secondary-label text-xs">Select one or more options.</p>- ) : null}- <div className="mt-2 space-y-0.5">+ {/* Rows span the header row's width so the radios align with the question text and the shortcut column sits under the dismiss button. */}+ <div className="-ms-2 mt-1.5 sm:-ms-1.5">{activeQuestion.options.map((option, index) => {const optionValue = option.value ?? option.label;const isOptimisticallySelected =@@ -250,33 +250,32 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(optimisticSingleSelect.optionValue === optionValue;const isSelected =isOptimisticallySelected || draftSelectedOptions?.[index] === true;- const shortcutKey = index < 9 ? index + 1 : null;const className = cn(- "group flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-left outline-none transition-colors duration-150 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary/25",- isSelected- ? "bg-muted/55 text-foreground"- : "bg-transparent text-foreground/85 hover:bg-muted/30",+ "group flex w-full items-start gap-2.5 rounded-md bg-transparent py-1.5 ps-2 text-left sm:ps-1.5 outline-none transition-colors duration-150 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary/25",+ isSelected ? "text-foreground" : "text-foreground/70 hover:bg-muted/30",(disabled || isResponding) && "opacity-50 cursor-not-allowed",!disabled && !isResponding && "cursor-pointer",);+ // The h-5 slots match the label's line box, so the indicator and shortcut stay on its first line.const content = (<>+ <span className="pointer-events-none flex h-5 shrink-0 items-center">+ {activeQuestion.multiSelect ? (+ <CheckboxMark checked={isSelected} />+ ) : (+ <OptionRadio checked={isSelected} />+ )}+ </span><div className="min-w-0 flex-1 flex flex-col gap-0.5"><span className="text-sm font-medium">{option.label}</span>{option.description && option.description !== option.label ? (<span className="text-secondary-label text-2xs">{option.description}</span>) : null}</div>- {isSelected ? (- <CheckIcon className="size-3.5 shrink-0 text-primary" />- ) : shortcutKey !== null ? (- <kbd- className={cn(- "flex size-5 shrink-0 items-center justify-center text-3xs font-medium text-muted-foreground tabular-nums",- )}- >- {shortcutKey}- </kbd>+ {index < 9 ? (+ <span className="flex h-5 w-7 shrink-0 items-center justify-center sm:w-6">+ <Kbd>{index + 1}</Kbd>+ </span>) : null}</>);@@ -284,6 +283,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(<buttonkey={`${activeQuestion.id}:${optionValue}`}type="button"+ aria-pressed={isSelected}disabled={disabled || isResponding}onClick={() => {handleOptionSelection(activeQuestion.id, optionValue);@@ -301,3 +301,21 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(</Collapsible>);});++// Drawn with ui/radio-group's look instead of using its Radio: Radio only checks inside a+// RadioGroup, whose arrow keys select options and would trip the single-select auto-advance.+function OptionRadio({ checked }: { checked: boolean }) {+ return (+ <span+ aria-hidden+ className={cn(+ "relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-full border border-input bg-background not-dark:bg-clip-padding sm:size-4 dark:bg-input/32",+ checked ? "shadow-none" : "shadow-xs/5",+ )}+ >+ {checked ? (+ <span className="-inset-px absolute flex items-center justify-center rounded-full bg-primary before:size-2 before:rounded-full before:bg-primary-foreground sm:before:size-1.5" />+ ) : null}+ </span>+ );+}diff --git a/apps/web/src/components/ui/checkbox.tsx b/apps/web/src/components/ui/checkbox.tsxindex 970432f8532..c7eb2bcfdda 100644--- a/apps/web/src/components/ui/checkbox.tsx+++ b/apps/web/src/components/ui/checkbox.tsx@@ -2,19 +2,22 @@ import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";import { cn } from "~/lib/utils";+const rootClassName =+ "relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-[.25rem] border border-input bg-background not-dark:bg-clip-padding shadow-xs/5 outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[3px] not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-ring aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:outline-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:focus-visible:aria-invalid:outline-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none";++const indicatorClassName =+ "-inset-px absolute flex items-center justify-center rounded-[.25rem] text-primary-foreground data-unchecked:hidden data-checked:bg-primary data-indeterminate:text-foreground in-[[data-slot=checkbox]:focus-visible]:inset-shadow-[0_0_0_3px_var(--background)] in-[[data-slot=checkbox]:focus-visible]:outline-2 in-[[data-slot=checkbox]:focus-visible]:outline-solid in-[[data-slot=checkbox]:focus-visible]:-outline-offset-2 in-[[data-slot=checkbox]:focus-visible]:outline-inherit";+function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {return (<CheckboxPrimitive.Root- className={cn(- "relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-[.25rem] border border-input bg-background not-dark:bg-clip-padding shadow-xs/5 outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[3px] not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-ring aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:outline-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:focus-visible:aria-invalid:outline-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",- className,- )}+ className={cn(rootClassName, className)}data-slot="checkbox"{...props}>{/* Keep an inner gap in the focus outline. Explicit glyph colors resist row icon-muting rules. */}<CheckboxPrimitive.Indicator- className="-inset-px absolute flex items-center justify-center rounded-[.25rem] text-primary-foreground data-unchecked:hidden data-checked:bg-primary data-indeterminate:text-foreground in-[[data-slot=checkbox]:focus-visible]:inset-shadow-[0_0_0_3px_var(--background)] in-[[data-slot=checkbox]:focus-visible]:outline-2 in-[[data-slot=checkbox]:focus-visible]:outline-solid in-[[data-slot=checkbox]:focus-visible]:-outline-offset-2 in-[[data-slot=checkbox]:focus-visible]:outline-inherit"+ className={indicatorClassName}data-slot="checkbox-indicator"render={(props, state) => (<span {...props}>@@ -56,4 +59,29 @@ function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {);}-export { Checkbox };+// Checkbox's look without its hidden input, for a row that is itself the button.+function CheckboxMark({ checked }: { checked: boolean }) {+ const state = checked ? { "data-checked": "" } : { "data-unchecked": "" };+ return (+ <span aria-hidden className={rootClassName} data-slot="checkbox" {...state}>+ <span className={indicatorClassName} data-slot="checkbox-indicator" {...state}>+ <svg+ className="size-3.5 text-current sm:size-3"+ fill="none"+ height="24"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="3"+ viewBox="0 0 24 24"+ width="24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path d="M5.252 12.7 10.2 18.63 18.748 5.37" />+ </svg>+ </span>+ </span>+ );+}++export { Checkbox, CheckboxMark };