Skip to content

feat: ScrollBar adds a showScrollBar field to determine if the scrollbar does not need to be hidden #300

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

Merged
merged 4 commits into from
Jan 21, 2025

Conversation

EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Jan 17, 2025

相关背景:
ant-design/ant-design#33915

Summary by CodeRabbit

  • 新功能

    • 为列表组件和滚动条组件添加了可控制滚动条显示的选项。
    • 用户现在可以通过 showScrollBar 属性决定是否显示滚动条。
  • 测试

    • 新增测试用例,验证当 showScrollBar 属性设置为 true 时滚动条的可见性。

Copy link

vercel bot commented Jan 17, 2025

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

Name Status Preview Comments Updated (UTC)
virtual-list ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 20, 2025 5:47am

Copy link

coderabbitai bot commented Jan 17, 2025

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.

src/List.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js
Error: Cannot find module '@umijs/fabric/dist/eslint'
Require stack:

  • /.eslintrc.js
  • /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/.eslintrc.js:1:14)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)

概述

遍历

此次更改为 ListScrollBar 组件引入了一个新的可选属性 showScrollBar,允许用户控制滚动条的可见性。通过在 ListPropsScrollBarProps 接口中添加此属性,组件现在可以根据用户偏好显示或隐藏滚动条。同时,在测试套件中添加了一个新的测试用例,以验证 showScrollBar 属性的功能。

变更

文件 变更摘要
src/List.tsx ListProps 接口中添加 `showScrollBar?: boolean
src/ScrollBar.tsx ScrollBarProps 接口中添加 `showScrollBar?: boolean
tests/scroll.test.js 添加新的测试用例,验证 showScrollBar 属性的行为

可能相关的 PR

诗歌

🐰 滚动条的魔法舞蹈
显示与隐藏,由你决定
一个属性,灵活控制
用户体验,如此轻盈
代码如诗,兔子欢笑 🎉


📜 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 52c189b and 1fa0edb.

📒 Files selected for processing (2)
  • src/List.tsx (4 hunks)
  • src/ScrollBar.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/List.tsx
  • src/ScrollBar.tsx

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:

  • 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. (Beta)
  • @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.

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: 1

🧹 Nitpick comments (1)
src/List.tsx (1)

643-643: 属性传递完整!

showScrollBar 属性被正确地传递给了垂直和水平滚动条组件。建议优化属性传递方式:

-showScrollBar={restProps?.showScrollBar}
+showScrollBar={showScrollBar}

这样可以:

  • 避免从 restProps 中读取属性
  • 提高代码可读性
  • 确保类型安全

Also applies to: 662-662

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c2ce7ce and d1f2144.

📒 Files selected for processing (3)
  • src/List.tsx (3 hunks)
  • src/ScrollBar.tsx (3 hunks)
  • tests/scroll.test.js (1 hunks)
🔇 Additional comments (3)
tests/scroll.test.js (1)

236-254: 测试用例覆盖了新功能!

测试用例完整地验证了 showScrollBar 属性的功能,包括:

  • 正确设置属性值
  • 验证滚动条可见性
  • 使用 act 处理异步更新
src/List.tsx (1)

75-75: 接口定义清晰!

showScrollBar 属性的类型定义正确且位置恰当。

src/ScrollBar.tsx (1)

21-21: 接口扩展合理!

ScrollBarProps 接口中新增的 showScrollBar 属性定义准确。

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

♻️ Duplicate comments (1)
src/ScrollBar.tsx (1)

62-66: 🛠️ Refactor suggestion

可见性控制逻辑需要优化

当前实现存在以下问题:

  1. 初始状态直接使用 showScrollBar 可能导致类型不匹配
  2. delayHidden 函数的提前返回逻辑可能影响现有行为

建议如下改进:

-const [visible, setVisible] = React.useState(false);
+const [visible, setVisible] = React.useState(showScrollBar === true);

 const delayHidden = () => {
   clearTimeout(visibleTimeoutRef.current);
-  setVisible(true);
+  if (showScrollBar === true) {
+    setVisible(true);
+    return;
+  }
   
-  if (showScrollBar === 'optional') {
-    visibleTimeoutRef.current = setTimeout(() => {
-      setVisible(false);
-    }, 3000);
-  }
+  setVisible(true);
+  visibleTimeoutRef.current = setTimeout(() => {
+    setVisible(false);
+  }, 3000);
 }

这样可以:

  • 确保状态类型安全
  • 保持滚动条可见性的一致性
  • 提高代码健壮性
🧹 Nitpick comments (1)
src/ScrollBar.tsx (1)

21-21: 需要为新属性添加文档注释

建议为 showScrollBar 属性添加 JSDoc 注释,说明:

  • 属性的用途和影响
  • 可选值的具体含义
  • 默认行为说明

示例:

+/**
+ * 控制滚动条的显示行为
+ * @property {(true | 'optional')} [showScrollBar='optional']
+ * - true: 滚动条始终可见
+ * - 'optional': 滚动条在不活动时自动隐藏
+ */
 showScrollBar?: true | 'optional';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d1f2144 and dd7acdb.

📒 Files selected for processing (2)
  • src/List.tsx (3 hunks)
  • src/ScrollBar.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/List.tsx
🔇 Additional comments (1)
src/ScrollBar.tsx (1)

42-42: 默认值设置合理

showScrollBar 默认值设置为 'optional' 是个不错的选择:

  • 保持了向后兼容性
  • 维持了原有的滚动条行为

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: 1

🧹 Nitpick comments (1)
src/ScrollBar.tsx (1)

21-21: 需要为新属性添加文档注释!

建议为 showScrollBar 属性添加 JSDoc 注释,说明:

  • 属性的用途
  • true'optional' 两个值的具体行为差异
  • 默认值说明

示例:

+/**
+ * 控制滚动条的显示行为
+ * @default 'optional'
+ * @param {'optional'} - 滚动条在不使用时自动隐藏
+ * @param {true} - 滚动条始终显示
+ */
 showScrollBar?: true | 'optional';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dd7acdb and 52c189b.

📒 Files selected for processing (2)
  • src/List.tsx (4 hunks)
  • src/ScrollBar.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/List.tsx
🔇 Additional comments (1)
src/ScrollBar.tsx (1)

60-65: 🛠️ Refactor suggestion

可见性控制逻辑需要优化!

当前实现存在以下问题:

  1. showScrollBar === true 时直接返回,但不更新 visible 状态
  2. 可能导致滚动条显示状态不一致

建议如下改进:

 const delayHidden = () => {
-  if (showScrollBar === true) return;
+  if (showScrollBar === true) {
+    setVisible(true);
+    return;
+  }
   clearTimeout(visibleTimeoutRef.current);
   setVisible(true);
   visibleTimeoutRef.current = setTimeout(() => {
     setVisible(false);
   }, 3000);
 };

这样可以:

  • 确保 showScrollBar === true 时滚动条始终可见
  • 保持状态一致性
  • 提高代码可维护性

Likely invalid or redundant comment.

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.51%. Comparing base (c2ce7ce) to head (1fa0edb).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #300   +/-   ##
=======================================
  Coverage   97.50%   97.51%           
=======================================
  Files          19       19           
  Lines         802      804    +2     
  Branches      187      193    +6     
=======================================
+ Hits          782      784    +2     
  Misses         20       20           

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

@MadCcc MadCcc merged commit ddf436f into react-component:master Jan 21, 2025
11 checks passed
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.

3 participants