Skip to content

[lexical-react] Bug Fix: Let Shift+Tab through an open typeahead menu - #9974

Open
GiorgioPorgio wants to merge 1 commit into
meta:mainfrom
GiorgioPorgio:fix/typeahead-shift-tab
Open

GiorgioPorgio wants to merge 1 commit into
meta:mainfrom
GiorgioPorgio:fix/typeahead-shift-tab

Conversation

@GiorgioPorgio

Copy link
Copy Markdown

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 #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.

## 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.
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
lexical Ready Ready Preview Nov 23, 2026 5:52pm UTC
lexical-playground Ready Ready Preview Nov 23, 2026 5:52pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 23, 2026
@rootnode-bot

rootnode-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 23, 2026, 6:08 PM UTC

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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:

  1. An e2e case for the real key path (packages/lexical-playground/__tests__/e2e/Mentions.spec.mjs). The unit test dispatches KEY_TAB_COMMAND directly, which is the right tier for the handler itself, but nothing exercises keydown through to TabIndentationExtension. 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.
  2. 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-activedescendant that updateSelectedIndex set 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.

Automated review (maintainer link)

@GiorgioPorgio

Copy link
Copy Markdown
Author

I would skip the e2e as each step of that path already has a test. Core dispatches Shift+Tab as KEY_TAB_COMMAND (keyDownDispatchParity.ts). Shift+Tab indentation has its own tests. The menu's part is the new unit test.

Happy to fix closing the menu on blur in a separate PR, as it's out of scope imo.

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9974

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9974

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9974

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9974

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9974

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9974

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9974

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9974

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9974

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9974

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9974

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9974

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9974

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9974

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9974

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9974

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9974

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9974

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9974

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9974

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9974

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9974

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9974

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9974

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9974

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9974

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9974

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9974

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9974

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9974

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9974

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9974

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9974

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9974

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9974

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9974

commit: 1092a94

This branch was successfully deployed

2 active deployments
Preview – lexical — 1092a94a Deployed Nov 23, 2026 by vercel[bot]
Preview – lexical-playground — 1092a94a Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant