Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

fix(chat): choice questions shown as app icons let you type your own answer or skip again (#17136)

Hazem Adel2c1d73630a13
diff --git a/packages/web/src/app/routes/chat-with-ai/components/multi-question-form.tsx b/packages/web/src/app/routes/chat-with-ai/components/multi-question-form.tsx
index 998165d47dc..b46a335e180 100644
--- a/packages/web/src/app/routes/chat-with-ai/components/multi-question-form.tsx
+++ b/packages/web/src/app/routes/chat-with-ai/components/multi-question-form.tsx
@@ -301,144 +301,146 @@ function ChoiceBody({
(o) => (!!o.icon || !!o.piece) && o.label.length <= MAX_ICON_GRID_LABEL,
);
- if (useIconGrid) {
- return (
- <div className="grid grid-cols-2 gap-2 sm:grid-cols-3">
- {options.map((option) => {
- const selected = answer === option.label;
- return (
- <button
- key={option.label}
- type="button"
- onClick={() => onPick(option.label)}
- aria-pressed={selected}
- className={cn(
- 'flex flex-col items-center gap-2 rounded-xl border border-gray-6/60 px-3 py-4 text-center text-sm transition-colors hover:bg-gray-3',
- selected && 'border-accent-7 bg-accent-3 hover:bg-accent-4',
- )}
- >
- <OptionIcon
- piece={option.piece}
- icon={option.icon}
- selected={selected}
- variant="grid"
- />
- <span className="leading-snug">{option.label}</span>
- </button>
- );
- })}
- </div>
- );
- }
-
return (
<div>
- <div role="menu" aria-label={question.question} className="gap-0">
- {options.map((option, i) => {
- const selected = answer === option.label;
- const isFirst = i === 0;
- const isLast = i === options.length - 1;
- return (
- <Fragment key={option.label}>
- {i > 0 && (
- <div className="px-3">
- <Separator
- className={cn(
- 'bg-gray-6/60 transition-opacity duration-150',
- isMidSepHidden(i) && 'opacity-0',
- )}
- />
- </div>
- )}
- <div
- role="menuitemradio"
- tabIndex={
- focusedRow === i || (focusedRow === null && isFirst) ? 0 : -1
- }
- aria-checked={selected}
- ref={(el) => {
- optionRefs.current[i] = el;
- if (isFirst) setFirstOptionEl(el);
- if (isLast) lastOptionRef.current = el;
- }}
+ {useIconGrid ? (
+ <div className="grid grid-cols-2 gap-2 sm:grid-cols-3">
+ {options.map((option) => {
+ const selected = answer === option.label;
+ return (
+ <button
+ key={option.label}
+ type="button"
onClick={() => onPick(option.label)}
- onMouseEnter={() => setHoveredRow(i)}
- onMouseLeave={() =>
- setHoveredRow((prev) => (prev === i ? null : prev))
- }
- onFocus={() => setFocusedRow(i)}
- onBlur={() =>
- setFocusedRow((prev) => (prev === i ? null : prev))
- }
- onKeyDown={(e) => {
- if (e.key === 'Enter') {
- e.preventDefault();
- onPick(option.label);
- return;
- }
- if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
- e.preventDefault();
- return;
- }
- if (e.key === 'ArrowDown') {
- e.preventDefault();
- if (isLast) {
- customAnswerInputRef.current?.focus();
- } else {
- setFocusedRow(i + 1);
- optionRefs.current[i + 1]?.focus();
- }
- return;
- }
- if (e.key === 'ArrowUp') {
- e.preventDefault();
- if (isFirst) {
- customAnswerInputRef.current?.focus();
- } else {
- setFocusedRow(i - 1);
- optionRefs.current[i - 1]?.focus();
- }
- return;
- }
- }}
+ aria-pressed={selected}
className={cn(
- 'group flex items-center gap-3 rounded-xl px-2 py-2 text-sm font-normal cursor-pointer transition-colors hover:bg-gray-3 outline-none',
- focusedRow === i && !selected && 'bg-gray-3 hover:bg-gray-4',
- selected && 'bg-gray-4 hover:bg-gray-5',
+ 'flex flex-col items-center gap-2 rounded-xl border border-gray-6/60 px-3 py-4 text-center text-sm transition-colors hover:bg-gray-3',
+ selected && 'border-accent-7 bg-accent-3 hover:bg-accent-4',
)}
>
- {option.piece || option.icon ? (
- <OptionIcon
- piece={option.piece}
- icon={option.icon}
- selected={selected || focusedRow === i}
- variant="list"
- />
- ) : (
- <span
- aria-hidden
- className={cn(
- 'flex size-8 shrink-0 items-center justify-center rounded-md bg-gray-5 text-xs font-medium text-gray-11 transition-colors',
- focusedRow === i && 'bg-gray-12 text-gray-1',
- selected && 'bg-gray-12 text-gray-1',
- )}
- >
- {i + 1}
- </span>
+ <OptionIcon
+ piece={option.piece}
+ icon={option.icon}
+ selected={selected}
+ variant="grid"
+ />
+ <span className="leading-snug">{option.label}</span>
+ </button>
+ );
+ })}
+ </div>
+ ) : (
+ <div role="menu" aria-label={question.question} className="gap-0">
+ {options.map((option, i) => {
+ const selected = answer === option.label;
+ const isFirst = i === 0;
+ const isLast = i === options.length - 1;
+ return (
+ <Fragment key={option.label}>
+ {i > 0 && (
+ <div className="px-3">
+ <Separator
+ className={cn(
+ 'bg-gray-6/60 transition-opacity duration-150',
+ isMidSepHidden(i) && 'opacity-0',
+ )}
+ />
+ </div>
)}
- <span className="flex-1 min-w-0 leading-snug">
- <span className="block">{option.label}</span>
- {option.description && (
- <span className="block text-xs text-gray-11">
- {option.description}
+ <div
+ role="menuitemradio"
+ tabIndex={
+ focusedRow === i || (focusedRow === null && isFirst)
+ ? 0
+ : -1
+ }
+ aria-checked={selected}
+ ref={(el) => {
+ optionRefs.current[i] = el;
+ if (isFirst) setFirstOptionEl(el);
+ if (isLast) lastOptionRef.current = el;
+ }}
+ onClick={() => onPick(option.label)}
+ onMouseEnter={() => setHoveredRow(i)}
+ onMouseLeave={() =>
+ setHoveredRow((prev) => (prev === i ? null : prev))
+ }
+ onFocus={() => setFocusedRow(i)}
+ onBlur={() =>
+ setFocusedRow((prev) => (prev === i ? null : prev))
+ }
+ onKeyDown={(e) => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ onPick(option.label);
+ return;
+ }
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
+ e.preventDefault();
+ return;
+ }
+ if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ if (isLast) {
+ customAnswerInputRef.current?.focus();
+ } else {
+ setFocusedRow(i + 1);
+ optionRefs.current[i + 1]?.focus();
+ }
+ return;
+ }
+ if (e.key === 'ArrowUp') {
+ e.preventDefault();
+ if (isFirst) {
+ customAnswerInputRef.current?.focus();
+ } else {
+ setFocusedRow(i - 1);
+ optionRefs.current[i - 1]?.focus();
+ }
+ return;
+ }
+ }}
+ className={cn(
+ 'group flex items-center gap-3 rounded-xl px-2 py-2 text-sm font-normal cursor-pointer transition-colors hover:bg-gray-3 outline-none',
+ focusedRow === i &&
+ !selected &&
+ 'bg-gray-3 hover:bg-gray-4',
+ selected && 'bg-gray-4 hover:bg-gray-5',
+ )}
+ >
+ {option.piece || option.icon ? (
+ <OptionIcon
+ piece={option.piece}
+ icon={option.icon}
+ selected={selected || focusedRow === i}
+ variant="list"
+ />
+ ) : (
+ <span
+ aria-hidden
+ className={cn(
+ 'flex size-8 shrink-0 items-center justify-center rounded-md bg-gray-5 text-xs font-medium text-gray-11 transition-colors',
+ focusedRow === i && 'bg-gray-12 text-gray-1',
+ selected && 'bg-gray-12 text-gray-1',
+ )}
+ >
+ {i + 1}
</span>
)}
- </span>
- </div>
- </Fragment>
- );
- })}
- </div>
+ <span className="flex-1 min-w-0 leading-snug">
+ <span className="block">{option.label}</span>
+ {option.description && (
+ <span className="block text-xs text-gray-11">
+ {option.description}
+ </span>
+ )}
+ </span>
+ </div>
+ </Fragment>
+ );
+ })}
+ </div>
+ )}
{allowCustom && (
<>
@@ -488,14 +490,14 @@ function ChoiceBody({
}}
onChange={(e) => setAnswer(e.target.value)}
onKeyDown={(e) => {
- if (e.key === 'ArrowUp') {
+ if (e.key === 'ArrowUp' && lastOptionRef.current) {
e.preventDefault();
- lastOptionRef.current?.focus();
+ lastOptionRef.current.focus();
return;
}
- if (e.key === 'ArrowDown') {
+ if (e.key === 'ArrowDown' && firstOptionRef.current) {
e.preventDefault();
- firstOptionRef.current?.focus();
+ firstOptionRef.current.focus();
return;
}
if (e.key === 'Enter' && (answer ?? '').trim()) {
diff --git a/packages/web/test/app/routes/chat-with-ai/multi-question-form-icon-grid.test.tsx b/packages/web/test/app/routes/chat-with-ai/multi-question-form-icon-grid.test.tsx
new file mode 100644
index 00000000000..2b0d6a0b781
--- /dev/null
+++ b/packages/web/test/app/routes/chat-with-ai/multi-question-form-icon-grid.test.tsx
@@ -0,0 +1,55 @@
+/**
+ * @vitest-environment jsdom
+ */
+import { cleanup, fireEvent, render, screen } from '@testing-library/react';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import { MultiQuestionForm } from '@/app/routes/chat-with-ai/components/multi-question-form';
+import { MultiQuestion } from '@/features/chat/lib/chat-store-types';
+
+vi.mock('i18next', () => ({ t: (key: string) => key }));
+
+afterEach(() => {
+ cleanup();
+});
+
+describe('MultiQuestionForm icon grid', () => {
+ it('lets you type your own answer under the icon grid', () => {
+ const onSubmit = vi.fn();
+ render(
+ <MultiQuestionForm questions={[ICON_QUESTION]} onSubmit={onSubmit} />,
+ );
+
+ fireEvent.change(screen.getByPlaceholderText('Type your answer...'), {
+ target: { value: 'Fastmail' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));
+
+ expect(onSubmit).toHaveBeenCalledWith('- **Which inbox?** Fastmail');
+ });
+
+ it('keeps arrow keys working in the answer field under the icon grid', () => {
+ render(<MultiQuestionForm questions={[ICON_QUESTION]} onSubmit={vi.fn()} />);
+ const input = screen.getByPlaceholderText('Type your answer...');
+
+ expect(fireEvent.keyDown(input, { key: 'ArrowUp' })).toBe(true);
+ expect(fireEvent.keyDown(input, { key: 'ArrowDown' })).toBe(true);
+ });
+
+ it('shows Skip under the icon grid', () => {
+ render(
+ <MultiQuestionForm questions={[ICON_QUESTION]} onSubmit={vi.fn()} />,
+ );
+
+ expect(screen.getByRole('button', { name: 'Skip' })).toBeTruthy();
+ });
+});
+
+const ICON_QUESTION: MultiQuestion = {
+ type: 'choice',
+ question: 'Which inbox?',
+ options: [
+ { label: 'Gmail', icon: 'mail' },
+ { label: 'Outlook', icon: 'mail' },
+ ],
+};