Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tabs): 修复tabs异步设置titles滚动失效(#2351) #2369

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

ShuchenEason
Copy link
Contributor

@ShuchenEason ShuchenEason commented Jun 19, 2024

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

#2351

💡 需求背景和解决方案

问题背景:
在已有代码中,对于每个tabs里的titles,遍历渲染的时候会把item组件的 ref push到 titleItemsRef.current 中,这个current一直随着点击切换 tab 或 tab 的 titles 变化而累加,最终这个 current 会有很大的存储。
并且移动tab到视区中心的代码只从 index 获取此元素。所以在 tab 的titles先是较少(假设只有3个),后续变多(假设为8)时,假设要移动到第5个时,titleItemsRef.current 的第5个索引并没有这个元素,因此会滚动失效。

修复方案:
取 titleItemsRef.current 的最后/最新的内容,并获取最新的 titles 元素,从而使滚动正常。

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 缺陷修复
    • 更新了 Tabs 组件中 scrollIntoView 函数的逻辑,以正确计算需要滚动到视野内的标题项索引。

Copy link

coderabbitai bot commented Jun 19, 2024

Walkthrough

Tabs组件中的scrollIntoView函数已更新,以正确计算要滚动到视图中的标题项的索引。这使得用户在切换标签时能够更精确地定位到对应的标签。

Changes

文件路径 变更摘要
src/packages/tabs/tabs.tsx 更新 scrollIntoView 函数,改进计算索引的逻辑

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Tabs
    participant scrollIntoView

    User->>Tabs: Select a tab
    Tabs->>scrollIntoView: Call with index, immediate?
    scrollIntoView-->>Tabs: Calculate correct index
    Tabs-->>User: Tab smoothly scrolls into view
Loading

Poem

在标签间轻轻跳跃,
新算法让心欢悦。
滚动如画卷展开,
精准定位,无需等待。
代码如诗,功能齐辉,
用户体验,完美无缺。
🐇✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b32225e and 3809973.

Files selected for processing (1)
  • src/packages/tabs/tabs.tsx (1 hunks)
Additional context used
Biome
src/packages/tabs/tabs.tsx

[error] 192-192: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 205-217: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event. (lint/a11y/useKeyWithClickEvents)

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

Additional comments not posted (1)
src/packages/tabs/tabs.tsx (1)

104-109: 修复了 tabs 异步设置标题时滚动失效的问题。


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

Copy link

codecov bot commented Jun 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.99%. Comparing base (b32225e) to head (3809973).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #2369   +/-   ##
=======================================
  Coverage   85.99%   85.99%           
=======================================
  Files         217      217           
  Lines       22821    22823    +2     
  Branches     2539     2539           
=======================================
+ Hits        19624    19626    +2     
  Misses       3192     3192           
  Partials        5        5           

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (3)
src/packages/tabs/tabs.tsx (3)

Line range hint 192-192: 建议使用可选链来提高代码的安全性和可读性。

- if (String(value) !== String(child.props.value || idx) && autoHeight)
+ if (String(value) !== String(child.props.value || idx)?.autoHeight)

Line range hint 205-217: 为了提高无障碍访问性,请确保使用鼠标事件的同时,添加相应的键盘事件处理。

+ onKeyUp={handleKeyUp}

Line range hint 1-250: 整体来看,组件结构合理,功能实现符合预期。建议增加更多的代码注释,以提高代码的可读性和可维护性。

@xiaoyatong xiaoyatong merged commit 327e639 into jdf2e:next Jun 21, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants