Skip to content

fix: preserve reverse tab navigation - #267

Open
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/preserve-shift-tab-navigation
Open

fix: preserve reverse tab navigation#267
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/preserve-shift-tab-navigation

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 27, 2026

Copy link
Copy Markdown

Summary\n\n- close an open dropdown when the user presses Shift+Tab\n- leave the event uncancelled so the browser can continue reverse focus navigation\n- retain the existing forward Tab behavior that moves focus into the overlay\n- add a regression covering focus, visibility, and default-prevention behavior\n\n## Problem\n\nThe global Tab handler currently calls focusMenu() whenever the overlay has not yet received focus. It does this for both Tab and Shift+Tab. As a result, Shift+Tab from the trigger is prevented and focus is forced forward into the menu instead of allowing the user to move to the previous control.\n\n## Validation\n\n- exact-base causal probe: the new regression fails because defaultPrevented is true and focusMenu() runs\n- fixed head: forward Tab and Shift+Tab keyboard tests pass\n- all 20 non-snapshot basic tests pass\n- point and props suites pass (2 tests)\n- npm run tsc\n- npm run compile (ESM, CommonJS, and declarations)\n- focused ESLint, Prettier, and git diff --check\n\nWith the currently resolved dependency tree, the untouched simply works snapshot expects old rc-menu generated ids while rc-menu now emits rc-menu-uuid-test-id-*; that same unrelated snapshot drift was present before the product-code fix and was not modified here.\n\nAI assistance disclosure: Codex was used to trace the focus handler, construct the red/green regression, audit open-PR overlap, run validation, and draft this description. I verified the event cancellation, focus target, menu state, exact diff, and test results directly.

Summary by CodeRabbit

  • Bug Fixes

    • 优化下拉菜单的键盘导航:按下 Shift+Tab 时,菜单会关闭并将焦点返回触发按钮。
    • 保留浏览器默认的 Shift+Tab 行为,提升键盘操作体验。
  • Tests

    • 增加键盘交互测试,验证菜单关闭、焦点返回及默认事件处理。
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f7175484-d7e6-4314-a885-e580ecd9f347

📥 Commits

Reviewing files that changed from the base of the PR and between f6175d2 and 74959fb.

📒 Files selected for processing (2)
  • src/hooks/useAccessibility.ts
  • tests/basic.test.tsx

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

下拉菜单现在会在按下 Shift+Tab 时关闭,并将焦点返回触发按钮。新增测试验证菜单状态、焦点位置和默认事件行为。普通 Tab 行为保持不变。

Changes

下拉菜单键盘交互

Layer / File(s) Summary
Shift+Tab 关闭菜单与焦点验证
src/hooks/useAccessibility.ts, tests/basic.test.tsx
handleKeyDown 在 Shift+Tab 时调用 handleCloseMenuAndReturnFocus(),并跳过菜单聚焦逻辑。测试验证默认事件未被阻止、触发按钮保持焦点且菜单已隐藏。

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 74959

The change preserves forward Tab behavior while allowing Shift+Tab to close the dropdown and continue normal reverse focus navigation. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: afc163

Poem

小兔按下 Shift+Tab,
菜门轻轻合上啦。
焦点跳回按钮旁,
默认行为未受伤。
测试点头说:通过!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:修复下拉菜单中的反向 Tab 导航,并与代码和测试变更一致。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant