LibreChat/client
Marco Beretta f51ea67ab4
⌨️ feat: Keyboard Submit, Focus and Escape for Ask User Cards (#17231)
* ⌨️ feat: Keyboard submit for ask_user_question answer box

The interactive ask_user_question card's answer textarea had no key
handling, so the answer could only be submitted by clicking. Route its
keydown through resolveComposerKeyDown so it follows the composer's
Enter-to-send preference, a rebound submit chord, and IME composition.
The run is paused rather than generating, so it resolves as idle and
Ctrl/Cmd+Enter submits instead of reaching the during-run actions.

* ⌨️ feat: Keyboard focus and confirm for batched ask_user_question

- Focus the first question's controls when a batch arrives, only when
  focus is idle (body, or the empty composer that sent the turn), and
  focus into the next step on advance instead of the fieldset: the picked
  or first option, else the answer field.
- Enter on the already-picked single-select option confirms the step;
  Enter on an unpicked option stays its click, so a pick never submits
  by itself (WCAG 3.2.2). Multi-select rows only toggle.
- Ctrl/Cmd+Enter confirm from the answer field like Enter; Shift+Enter
  never does.

* 🐛 fix: Keep Held Enter and Remounts From Picking Batched Answers

Review findings on the batched ask_user_question card, and what this
commit does about each.

1. Held or double-tapped Enter could pick answers and submit the batch.
   After Enter confirmed a step, focus moved to the next step's first
   option. A keyboard Enter on a focused button is its click, so the
   key repeat of a held Enter (or a quick double-tap) picked that option
   and advanced again. On the last step the next repeat landed on the
   now-pressed option, confirmed it, and submitted the whole batch with
   answers the user never chose.

   Fix: after a step change, focus goes to the step's picked option,
   else its answer field. An unpicked option is only a focus target when
   a batch first arrives. Repeats now reach a text field, which can page
   on but never picks an option or submits on the user's behalf.

2. Focus-on-arrival ran on every mount, not only on arrival. Its effect
   has empty deps, so moving the batch between the composer popover and
   the chat card, or remounting a message that still holds an
   unanswered batch (reopening a conversation, a Share view), pulled
   focus onto an option of that batch. The next Enter or Space would
   then answer it.

   Fix: `AskUserQuestions` takes a `focusOnArrival` prop, set only by
   the surface showing the live pause (the popover, or the chat card
   while it is live and visible), so other mounts never take focus.
   Focus is placed at most once per batch, tracked by action id, so a
   move between surfaces is not treated as a new arrival.

Tests: a held Enter from an answer field picks nothing and never
submits; a surface that isn't the live pause leaves focus alone; a
remount of the same batch doesn't take focus again. All three fail
without this change. The Chat/Messages/Content, Chat/Input, Chat/ask
and hooks/Input suites pass, apart from TokenUsage/index.spec.tsx,
which fails the same way without this change. tsc, ESLint and Prettier
are clean on the changed files.

* feat: Escape to Skip Ask Cards and Move the Popover to Chat

Escape in the chat card skips the question or batch, but only before
anything is entered, so a stray Escape cannot discard an answer and
resume the run. Escape with focus inside the composer popover moves the
question to the chat, as it already did from the composer, and returns
focus to the composer once the popover closes. Also drops the em dashes
from the batched card's comments.

* fix: Read Enter-to-Send From the Chat Surface Host in the Ask Card

* test: Cover Ask Batch Keyboard Control in E2E Scenarios

* fix: Keep Held and Modified Enter From Submitting Ask Answers

Ignore auto-repeated Enter before confirming a picked option, so a held
Enter cannot both pick and submit the last question. In the answer
field, Shift, Alt and repeated Enter now prevent the enclosing chat
form's implicit submit instead of returning early. Escape that cancels
an IME composition no longer moves the popover to the chat, and the
arrival-focus flag lives in the batch's Jotai form state.

* fix: Honor a Submit Shortcut Rebound Off Enter in Ask Answer Fields

The window shortcut handler yields submitMessage in every editing field
except the composer, so a chord such as Ctrl+J did nothing in the ask
answer fields. Both the single-question answer box and the batched
answer field now act on it, through a shared isReboundSubmitChord.

---------

Co-authored-by: elie605 <ebtien@gmail.com>
2026-10-18 20:17:36 +02:00
..
public 🐛 fix: Restore MCP App Rendering and Actions (#16382) 2026-10-16 13:27:29 -07:00
src ⌨️ feat: Keyboard Submit, Focus and Escape for Ask User Cards (#17231) 2026-10-18 20:17:36 +02:00
sw
test 🧱 refactor: Read Message Content Siblings Through the Parts Host (#17171) 2026-10-16 22:05:25 +02:00
babel.config.cjs
check_updates.sh
index.html 🎨 feat: Paint the Operator Theme on a First-Ever Visit (#16962) 2026-10-14 13:16:44 +02:00
jest.config.cjs 🚰 refactor: Move the Pure Stream Code into the @librechat/chat Core (#16979) 2026-10-11 23:04:47 +02:00
jest.resolver.cjs
nginx.conf
package.json 🧹 refactor: Remove Dead Client Hooks, Store Modules and Utilities (#17111) 2026-10-15 12:22:13 +02:00
postcss.config.cjs
tailwind.config.cjs 📦 feat: Scaffold the @librechat/chat Package (#16964) 2026-10-10 21:00:10 +02:00
tsconfig.json 🥟 ci: Type-Check Workspaces with bun check (#17009) 2026-10-12 06:40:07 -04:00
vite.config.ts 🎨 feat: Paint the Operator Theme on a First-Ever Visit (#16962) 2026-10-14 13:16:44 +02:00