@@ -3,6 +3,7 @@ import { memo, useCallback, useEffect, useRef, useState } from "react";
33import { type PendingUserInput } from "../../session-logic" ;
44import {
55 derivePendingUserInputProgress ,
6+ summarizePendingUserInputAnswer ,
67 type PendingUserInputDraftAnswer ,
78} from "../../pendingUserInput" ;
89import { CheckIcon } from "lucide-react" ;
@@ -17,7 +18,9 @@ interface PendingUserInputPanelProps {
1718 answers : Record < string , PendingUserInputDraftAnswer > ;
1819 questionIndex : number ;
1920 onToggleOption : ( questionId : string , optionValue : string ) => void ;
21+ /** Moves past an answered question; never called on the last one. */
2022 onAdvance : ( ) => void ;
23+ onSelectQuestion : ( questionIndex : number ) => void ;
2124 onDismiss : ( requestId : RuntimeRequestId ) => void ;
2225}
2326
@@ -29,6 +32,7 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
2932 questionIndex,
3033 onToggleOption,
3134 onAdvance,
35+ onSelectQuestion,
3236 onDismiss,
3337} : PendingUserInputPanelProps ) {
3438 if ( pendingUserInputs . length === 0 ) return null ;
@@ -45,6 +49,7 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
4549 questionIndex = { questionIndex }
4650 onToggleOption = { onToggleOption }
4751 onAdvance = { onAdvance }
52+ onSelectQuestion = { onSelectQuestion }
4853 onDismiss = { onDismiss }
4954 />
5055 ) ;
@@ -58,6 +63,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
5863 questionIndex,
5964 onToggleOption,
6065 onAdvance,
66+ onSelectQuestion,
6167 onDismiss,
6268} : {
6369 prompt : PendingUserInput ;
@@ -67,6 +73,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
6773 questionIndex : number ;
6874 onToggleOption : ( questionId : string , optionValue : string ) => void ;
6975 onAdvance : ( ) => void ;
76+ onSelectQuestion : ( questionIndex : number ) => void ;
7077 onDismiss : ( requestId : RuntimeRequestId ) => void ;
7178} ) {
7279 // Message-mode requests remain answerable after their provider turn ends.
@@ -126,6 +133,8 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
126133 return clearAutoAdvance ;
127134 } , [ activeQuestion ?. id , disabled ] ) ;
128135
136+ // Choosing an option moves on to the next question, but never submits: the
137+ // last question waits for Submit so a click can't send answers by accident.
129138 const handleOptionSelection = useCallback (
130139 ( questionId : string , optionValue : string ) => {
131140 if ( disabled || isResponding ) return ;
@@ -137,19 +146,20 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
137146 onToggleOption ( questionId , optionValue ) ;
138147 if ( autoAdvanceTimerRef . current !== null ) {
139148 window . clearTimeout ( autoAdvanceTimerRef . current ) ;
149+ autoAdvanceTimerRef . current = null ;
140150 }
151+ if ( progress . isLastQuestion ) return ;
141152 autoAdvanceTimerRef . current = window . setTimeout ( ( ) => {
142153 autoAdvanceTimerRef . current = null ;
143154 onAdvanceRef . current ( ) ;
144155 } , 200 ) ;
145156 } ,
146- [ activeQuestion , disabled , isResponding , onToggleOption ] ,
157+ [ activeQuestion , disabled , isResponding , onToggleOption , progress . isLastQuestion ] ,
147158 ) ;
148159
149- // Keyboard shortcut: number keys 1-9 select corresponding options when focus is
150- // outside editable fields. Multi-select prompts toggle options in place; single-
151- // select prompts keep the existing auto-advance behavior. Collapsed prompts opt
152- // out, since the numbers they refer to are not on screen.
160+ // Keyboard shortcuts when focus is outside editable fields: number keys 1-9
161+ // select the corresponding option, and left/right arrows switch questions.
162+ // Collapsed prompts opt out, since what the keys refer to is not on screen.
153163 useEffect ( ( ) => {
154164 if ( ! activeQuestion || responseDisabled || isCollapsed ) return ;
155165 const handler = ( event : globalThis . KeyboardEvent ) => {
@@ -164,6 +174,13 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
164174 ) {
165175 return ;
166176 }
177+ if ( event . key === "ArrowLeft" || event . key === "ArrowRight" ) {
178+ const nextIndex = progress . questionIndex + ( event . key === "ArrowLeft" ? - 1 : 1 ) ;
179+ if ( nextIndex < 0 || nextIndex >= prompt . questions . length ) return ;
180+ event . preventDefault ( ) ;
181+ onSelectQuestion ( nextIndex ) ;
182+ return ;
183+ }
167184 const digit = Number . parseInt ( event . key , 10 ) ;
168185 if ( Number . isNaN ( digit ) || digit < 1 || digit > 9 ) return ;
169186 const optionIndex = digit - 1 ;
@@ -175,7 +192,15 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
175192 } ;
176193 document . addEventListener ( "keydown" , handler ) ;
177194 return ( ) => document . removeEventListener ( "keydown" , handler ) ;
178- } , [ activeQuestion , handleOptionSelection , isCollapsed , responseDisabled ] ) ;
195+ } , [
196+ activeQuestion ,
197+ handleOptionSelection ,
198+ isCollapsed ,
199+ onSelectQuestion ,
200+ progress . questionIndex ,
201+ prompt . questions . length ,
202+ responseDisabled ,
203+ ] ) ;
179204
180205 if ( ! activeQuestion ) {
181206 return null ;
@@ -200,7 +225,9 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
200225 < ComposerBanner . Icon />
201226 < ComposerBanner . Content >
202227 < span className = "shrink-0 font-medium text-muted-foreground" >
203- { activeQuestion . header }
228+ { isCollapsed || prompt . questions . length === 1
229+ ? activeQuestion . header
230+ : `${ progress . answeredQuestionCount } of ${ prompt . questions . length } answered` }
204231 </ span >
205232 { isCollapsed ? (
206233 < span className = "min-w-0 flex-1 truncate text-secondary-label" >
@@ -209,7 +236,7 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
209236 ) : null }
210237 </ ComposerBanner . Content >
211238 < ComposerBanner . Actions >
212- { prompt . questions . length > 1 ? (
239+ { isCollapsed && prompt . questions . length > 1 ? (
213240 < span className = "text-3xs font-medium text-muted-foreground tabular-nums" >
214241 { questionIndex + 1 } /{ prompt . questions . length }
215242 </ span >
@@ -240,6 +267,45 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
240267 </ ComposerBanner . Actions >
241268 </ CollapsibleTrigger >
242269 < CollapsiblePanel >
270+ { prompt . questions . length > 1 ? (
271+ < ComposerBanner . Body className = "pe-1 pb-2" >
272+ < div
273+ role = "tablist"
274+ aria-label = "Questions"
275+ className = "flex gap-1 overflow-x-auto [scrollbar-width:none]"
276+ >
277+ { prompt . questions . map ( ( question , index ) => {
278+ const summary = summarizePendingUserInputAnswer ( question , answers [ question . id ] ) ;
279+ const isActive = index === progress . questionIndex ;
280+ return (
281+ < button
282+ key = { question . id }
283+ type = "button"
284+ role = "tab"
285+ aria-selected = { isActive }
286+ aria-label = { summary ? `${ question . header } : ${ summary } ` : question . header }
287+ data-pending-user-input-tab = { summary === null ? "unanswered" : "answered" }
288+ onClick = { ( ) => onSelectQuestion ( index ) }
289+ className = { cn (
290+ "flex max-w-48 min-w-0 shrink-0 cursor-pointer items-center gap-1 rounded-md px-2 py-1 text-2xs outline-none transition-colors duration-150 focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary/25" ,
291+ isActive
292+ ? "bg-muted/70 text-foreground"
293+ : "text-muted-foreground hover:bg-muted/30 hover:text-foreground/85" ,
294+ ) }
295+ >
296+ < span className = "shrink-0 font-medium" > { question . header } </ span >
297+ { summary !== null ? (
298+ < >
299+ < CheckIcon className = "size-3 shrink-0 text-primary" />
300+ < span className = "min-w-0 truncate text-secondary-label" > { summary } </ span >
301+ </ >
302+ ) : null }
303+ </ button >
304+ ) ;
305+ } ) }
306+ </ div >
307+ </ ComposerBanner . Body >
308+ ) : null }
243309 < ComposerBanner . Scroll >
244310 < ComposerBanner . Body className = "pe-1 pb-1 wrap-anywhere" >
245311 < p className = "text-sm text-foreground/85" > { activeQuestion . question } </ p >
0 commit comments