Repository navigation
[lexical-react] Bug Fix: Let Shift+Tab through an open typeahead menu - #9974
GiorgioPorgio wants to merge 1 commit into
Conversation
## Description `LexicalMenu` picks the highlighted option on Tab without checking Shift. Core sends `KEY_TAB_COMMAND` for Tab with or without Shift. That makes Shift+Tab pick too. The Enter handler already lets Shift through (added in meta#8489). This adds the same check to Tab. Shift+Tab now reaches the editor's own Tab handling or the browser. On the playground in rich text it inserts a tab via `TabIndentationExtension` and the menu closes. In plain text focus moves to the previous element. Affects every menu built on `LexicalMenu`: `LexicalTypeaheadMenuPlugin` and `LexicalNodeMenuPlugin` (used by `LexicalAutoEmbedPlugin`). Out of scope: a menu stays open when focus leaves the editor, the same as after a click outside. ## Changeset `[fix]` for `@lexical/react`, with a `Verify:` paragraph. ## Test plan ### Before ``` $ pnpm exec vitest run --project unit packages/lexical-react/src/__tests__/unit/LexicalMenu.test.tsx -t "Tab" × Shift+Tab leaves the key to the editor AssertionError: expected true to be false // Object.is equality Tests 1 failed | 1 passed | 18 skipped (20) ``` Playground (`pnpm run dev`, Playwright, headless Chromium), `@Luk` or `/` with the menu open, then Shift+Tab: picks the option in rich and plain text, the same as Tab (3 of 3 runs each). ### After ``` $ pnpm exec vitest run --project unit packages/lexical-react/src/__tests__/unit/LexicalMenu.test.tsx -t "Tab" Tests 2 passed | 18 skipped (20) $ pnpm run ci-check Found 0 errors $ pnpm run test-unit Tests 40554 passed | 423 expected fail | 174 skipped (41151) ``` Playground, same steps: Shift+Tab inserts a tab and closes the menu in rich text. In plain text it moves focus back. Tab still picks. Only Chromium was tested. Firefox and WebKit were not.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Thanks, this looks good. The Shift check in LexicalMenu's Tab handler mirrors the existing Shift+Enter fall-through, the new LexicalMenu.test.tsx case fails without the fix and passes with it, and on the playground Shift+Tab with the mention menu open now inserts a tab in rich text and moves focus back in plain text while Tab still picks, exactly as the changeset's Verify: paragraph says.
Two optional, non-blocking suggestions:
- An e2e case for the real key path (
packages/lexical-playground/__tests__/e2e/Mentions.spec.mjs). The unit test dispatchesKEY_TAB_COMMANDdirectly, which is the right tier for the handler itself, but nothing exercises keydown through toTabIndentationExtension. AGENTS.md ("Testing Strategy") puts behavior that needs the playground in the E2E tier; typing@Luk, pressing Shift+Tab and asserting there is no mention node (and a tab in rich text) would keep that integration from regressing. - Follow-up for the menu outliving focus. As the description notes, in an editor without a Tab handler Shift+Tab now moves focus out while the menu stays drawn, and the editor root keeps the
aria-activedescendantthatupdateSelectedIndexset until the menu unmounts (packages/lexical-react/src/shared/LexicalMenu.tsx, lines 372-380 and 419-426). Closing the menu on editor blur would tidy that up; it is fine as a separate PR.
|
I would skip the e2e as each step of that path already has a test. Core dispatches Shift+Tab as Happy to fix closing the menu on blur in a separate PR, as it's out of scope imo. |
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
Description
LexicalMenupicks the highlighted option on Tab without checking Shift. Core sendsKEY_TAB_COMMANDfor Tab with or without Shift. That makes Shift+Tab pick too.The Enter handler already lets Shift through (added in #8489). This adds the same check to Tab. Shift+Tab now reaches the editor's own Tab handling or the browser. On the playground in rich text it inserts a tab via
TabIndentationExtensionand the menu closes. In plain text focus moves to the previous element.Affects every menu built on
LexicalMenu:LexicalTypeaheadMenuPluginandLexicalNodeMenuPlugin(used byLexicalAutoEmbedPlugin).Out of scope: a menu stays open when focus leaves the editor, the same as after a click outside.
Changeset
[fix]for@lexical/react, with aVerify:paragraph.Test plan
Before
Playground (
pnpm run dev, Playwright, headless Chromium),@Lukor/with the menu open, then Shift+Tab: picks the option in rich and plain text, the same as Tab (3 of 3 runs each).After
Playground, same steps: Shift+Tab inserts a tab and closes the menu in rich text. In plain text it moves focus back. Tab still picks. Only Chromium was tested. Firefox and WebKit were not.