({
questions,
onSubmit,
onSkip,
})
| 30 | } |
| 31 | |
| 32 | export const MultipleChoiceForm: React.FC<MultipleChoiceFormProps> = ({ |
| 33 | questions, |
| 34 | onSubmit, |
| 35 | onSkip, |
| 36 | }) => { |
| 37 | const theme = useTheme() |
| 38 | const terminalFocused = useChatStore((state) => state.inputFocused) |
| 39 | const suppressNextHoverFocusRef = useRef(false) |
| 40 | |
| 41 | // Track which question is currently expanded (null = none) |
| 42 | const [expandedIndex, setExpandedIndex] = useState<number | null>( |
| 43 | questions.length > 0 ? 0 : null, |
| 44 | ) |
| 45 | |
| 46 | // Track answers for each question |
| 47 | const [answers, setAnswers] = useState<Map<number, AccordionAnswer>>( |
| 48 | new Map(), |
| 49 | ) |
| 50 | |
| 51 | // Track focused option within expanded question |
| 52 | const [focusedOptionIndex, setFocusedOptionIndex] = useState<number | null>( |
| 53 | questions.length > 0 ? 0 : null, |
| 54 | ) |
| 55 | |
| 56 | // Track which question has keyboard focus |
| 57 | const [focusedQuestionIndex, setFocusedQuestionIndex] = useState<number>(0) |
| 58 | |
| 59 | // Track if submit button has focus (Tab navigation) |
| 60 | const [submitFocused, setSubmitFocused] = useState<boolean>(false) |
| 61 | |
| 62 | const [submitHovered, setSubmitHovered] = useState<boolean>(false) |
| 63 | |
| 64 | const [showFocusHighlight, setShowFocusHighlight] = useState<boolean>(true) |
| 65 | |
| 66 | const [lastFocusBeforeSubmit, setLastFocusBeforeSubmit] = useState<{ |
| 67 | questionIndex: number |
| 68 | optionIndex: number |
| 69 | } | null>(null) |
| 70 | |
| 71 | // Track if user is typing in "Custom" text input |
| 72 | const [isTypingCustom, setIsTypingCustom] = useState<boolean>(false) |
| 73 | |
| 74 | // Track cursor position for "Custom" text input (per question) |
| 75 | const [customCursorPositions, setCustomCursorPositions] = useState<Map<number, number>>( |
| 76 | new Map(), |
| 77 | ) |
| 78 | |
| 79 | const setAnswerForQuestion = useCallback( |
| 80 | ( |
| 81 | questionIndex: number, |
| 82 | updater: (previous: AccordionAnswer | undefined) => AccordionAnswer, |
| 83 | ) => { |
| 84 | setAnswers((prev) => { |
| 85 | const nextAnswers = new Map(prev) |
| 86 | const previousAnswer = prev.get(questionIndex) ?? {} |
| 87 | nextAnswers.set(questionIndex, updater(previousAnswer)) |
| 88 | return nextAnswers |
| 89 | }) |
nothing calls this directly
no test coverage detected