Skip to content

fix(react-textarea): restore focus to textarea when hitting Escape in CMD+K popup - #3257

Merged
jpr5 merged 3 commits into
CopilotKit:mainfrom
hashwnath:fix/escape-key-focus-loss-399
Mar 6, 2026
Merged

jpr5 merged 3 commits into
CopilotKit:mainfrom
hashwnath:fix/escape-key-focus-loss-399

Conversation

@hashwnath

Copy link
Copy Markdown
Contributor

Fixes #399

When the CopilotTextarea hovering popup (CMD+K / CTRL+K) is open and the user presses Escape, the popup loses focus entirely, instead of safely closing and returning focus to the underlying textarea.

This PR:

  1. Adds an Escape key handler to the HoveringInsertionPromptBoxCore component so the textarea can intercept the key.
  2. Adds a document-level Escape listener to HoveringToolbar to cleanly close the popup and use ReactEditor.focus() to restore focus to the Slate editor.

Testing

  1. Run textarea example.
  2. Type in the input, press CMD+K (or CTRL+K).
  3. Press Escape.
  4. The popup closes and focus is successfully returned to the editor input without needing an extra mouse click.

@changeset-bot

changeset-bot Bot commented Feb 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d11d13f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@copilotkit/react-textarea Patch
@copilotkit/a2ui-renderer Patch
@copilotkit/react-core Patch
@copilotkit/react-ui Patch
@copilotkit/runtime-client-gql Patch
@copilotkit/runtime Patch
@copilotkit/sdk-js Patch
@copilotkit/shared Patch
@copilotkit/voice Patch
@copilotkitnext/agent Patch
@copilotkitnext/angular Patch
@copilotkitnext/core Patch
@copilotkitnext/demo-agents Patch
@copilotkitnext/eslint-config Patch
@copilotkitnext/react Patch
@copilotkitnext/runtime Patch
@copilotkitnext/shared Patch
@copilotkitnext/sqlite-runner Patch
@copilotkitnext/typescript-config Patch
@copilotkitnext/web-inspector Patch
@copilotkitnext/next-pages-router Patch
@copilotkitnext/node-express Patch
@copilotkit-storybook/angular Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

@hashwnath is attempting to deploy a commit to the CopilotKit Team on Vercel.

A member of the Team first needs to authorize it.

@jpr5 jpr5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix. Added a comment clarifying the dual-handler interaction for future spelunkers.

@jpr5
jpr5 merged commit 3d088cf into CopilotKit:main Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hitting "Escape" in CTRL + K window of CopilotTextarea loses focus of the input field

2 participants