Skip to content

Conversation

@afc163
Copy link
Member

@afc163 afc163 commented Apr 28, 2025

Summary by CodeRabbit

  • 样式
    • 优化了 Tab 组件键盘操作时的行为,按下 Enter 或空格键时将优先激活当前聚焦的标签页。
  • 文档
    • 示例代码中 tab 切换事件的回调函数名称由 onChange 更名为 onTabChange
  • 测试
    • 增强了无障碍相关测试,进一步验证了键盘激活标签页时回调函数的调用顺序与参数。

@vercel
Copy link

vercel bot commented Apr 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tabs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 28, 2025 10:15am

@coderabbitai
Copy link

coderabbitai bot commented Apr 28, 2025

Walkthrough

本次更改主要涉及 Tab 组件的键盘事件处理和相关回调函数命名的调整。Tab 切换时,按下 Enter 或 Space 键将优先以当前聚焦(focus)的标签页为准,而非总是激活(active)的标签页。示例代码中回调函数名称由 onChange 改为 onTabChange,并同步更新引用。测试用例也增加了对回调参数和调用次数的精确断言,确保键盘操作下的行为符合预期。

Changes

文件路径/分组 变更摘要
docs/examples/basic.tsx 回调函数 onChange 重命名为 onTabChange,并同步调整组件引用。
src/TabNavList/index.tsx 键盘事件处理逻辑变更,优先以 focusKey 调用 onTabClick
tests/accessibility.test.tsx 增加更多断言,验证回调参数及调用次数,细化键盘激活标签页的测试。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TabNavList
    participant Tabs
    User->>TabNavList: 按下 Enter/Space 键
    TabNavList->>TabNavList: 判断 focusKey 是否存在
    alt focusKey 存在
        TabNavList->>Tabs: onTabClick(focusKey, event)
    else focusKey 不存在
        TabNavList->>Tabs: onTabClick(activeKey, event)
    end
    Tabs->>Tabs: 处理回调逻辑
Loading

Suggested reviewers

  • zombieJ

Poem

🐇
键盘轻敲标签飞,
聚焦优先新规则。
回调更名更清晰,
测试细致不留疑。
小兔欢跳庆更新,
代码世界更聪明!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

docs/examples/basic.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected]_jest@29.7.0_@types[email protected][email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

src/TabNavList/index.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected]_jest@29.7.0_@types[email protected][email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

tests/accessibility.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected]_jest@29.7.0_@types[email protected][email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61c33aa and a36b27a.

📒 Files selected for processing (3)
  • docs/examples/basic.tsx (1 hunks)
  • src/TabNavList/index.tsx (1 hunks)
  • tests/accessibility.test.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/TabNavList/index.tsx (1)
docs/examples/mix.tsx (1)
  • activeKey (20-174)
🔇 Additional comments (6)
src/TabNavList/index.tsx (1)

378-378: 优化键盘无障碍:优先使用 focusKey 而非 activeKey

更改后,当用户按下 Enter 或 Space 键时,会优先激活当前焦点所在的标签页(focusKey),而不是总是激活已激活的标签页(activeKey)。这个改动符合键盘用户的期望行为,提高了无障碍体验。

docs/examples/basic.tsx (2)

44-46: 回调函数重命名为更具描述性的名称

onChange 重命名为 onTabChange,使函数名称更加明确其用途,提高代码可读性。


53-53: 组件属性更新以匹配重命名的回调函数

更新 Tabs 组件的 onChange 属性以使用重命名后的 onTabChange 函数。

tests/accessibility.test.tsx (3)

105-106: 增强测试:验证回调参数和调用次数

添加断言以确保 onTabClick 被调用时传递了正确的标签键值和事件对象,并且在此时 onChange 尚未被调用。这些断言验证了键盘事件处理的准确性。


114-116: 增强测试:验证切换标签时的回调行为

添加断言以确保当激活第二个标签时,onTabClick 被正确调用并传递了准确的参数,且 onChange 被调用一次并获得了正确的键值参数。


118-122: 增强测试:验证重复激活相同标签的行为

添加测试用例来验证在同一标签上再次按下 Enter 键时,onTabClick 会被再次调用(传递相同的键值),但 onChange 不会被再次触发。这确保了组件在重复操作时的行为符合预期。

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Apr 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.97%. Comparing base (61c33aa) to head (a36b27a).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #826   +/-   ##
=======================================
  Coverage   98.97%   98.97%           
=======================================
  Files          18       18           
  Lines         781      781           
  Branches      234      232    -2     
=======================================
  Hits          773      773           
  Misses          8        8           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@afc163 afc163 force-pushed the fix/tabs-focus-issue branch from 9c9f240 to a36b27a Compare April 28, 2025 10:14
@afc163 afc163 merged commit 278b7d7 into master Apr 28, 2025
10 checks passed
@afc163 afc163 deleted the fix/tabs-focus-issue branch April 28, 2025 10:18
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.

2 participants