Skip to content

feat(suggestion-menu): add the keymap and dismissal - #532

Merged
kianbazza merged 1 commit into
ui-560-add-suggestionmenu-with-its-handle-and-partsfrom
ui-561-add-the-suggestion-menu-keymap-and-dismissal
Sep 29, 2026
Merged

kianbazza merged 1 commit into
ui-560-add-suggestionmenu-with-its-handle-and-partsfrom
ui-561-add-the-suggestion-menu-keymap-and-dismissal

Conversation

@kianbazza

@kianbazza kianbazza commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

SuggestionMenu handles the keyboard from the host input, and closes when the user leaves it.

Key while open Result
↑/↓, Ctrl+N/P, Home/End Move the highlight
Enter Choose the highlighted row
Escape Close, without reaching an enclosing dialog
Tab, ←/→, typing, ⌘/Alt/Shift combinations, IME composition Stay with the host

The host passes key presses to handle.handleKeyDown(event), which returns true when the menu used the key. That matches how ProseMirror, CodeMirror and Lexical order their keymaps.

Dismissal:

  • The menu closes when focus leaves the host, but not when focus moves into the menu, when the window loses focus, or when the host gets focus back straight away. This also works in iframes and shadow roots.
  • Pressing inside the menu keeps focus in the host. Form fields inside the popup keep their own focus.
  • Choosing a row reports item-press even when the row's onSelect edits the text and the editor closes the menu from there. A close requested during Enter, or during a click on a row, waits until the menu's own close.

Evidence

suggestion-menu.keymap.test.tsx (22 tests):

  • One test for each row of the key table.
  • Escape stops before a document listener, with keys forwarded from a native listener.
  • Choosing by Enter and by click reports item-press once from a contenteditable host. A row that keeps the menu open still applies its own close().
  • Shadow-root hosts, a host attached before it's in the page, and a Root that unmounts right after focus leaves.

Checked in Chromium with ProseMirror:

  • Enter doesn't split the paragraph.
  • A real mouse click reports item-press once. Browsers run microtasks between event listeners, which jsdom doesn't reproduce, so this needed a real browser.
  • Escape reports escape-key, and clicking elsewhere reports outside-press.

Merge Danger

Door: two-way

Blast Radius: SuggestionMenu only

Closes UI-561

@vercel

vercel Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ui-canary Ready Ready Preview Sep 29, 2026 2:31pm UTC

Request Review

@linear-code

linear-code Bot commented Sep 29, 2026

Copy link
Copy Markdown

UI-561

@kianbazza
kianbazza force-pushed the ui-561-add-the-suggestion-menu-keymap-and-dismissal branch from f370507 to ef1848b Compare September 29, 2026 14:29
@kianbazza
kianbazza marked this pull request as ready for review September 29, 2026 14:45
@kianbazza
kianbazza merged commit bd83e7b into canary Sep 29, 2026
5 checks passed

This branch was successfully deployed

1 active deployment
Preview – ui-canary — ef1848b4 Deployed Sep 29, 2026 by vercel[bot]
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.

1 participant