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

feat:Using the showScrollBar property of the List component #1121

Closed
wants to merge 3 commits into from

Conversation

EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Feb 8, 2025

相关链接:ant-design/ant-design#33915

Summary by CodeRabbit

  • 新功能
    • 为下拉选择组件新增可配置滚动条选项,提升交互体验。
    • 优化标签展示,支持显示标签的索引信息,改善视觉识别。
  • 内务更新
    • 升级了部分依赖库,增强整体性能与稳定性。
  • 测试
    • 添加了针对滚动条显示及标签渲染功能的测试,确保新特性稳定运行。

Copy link

vercel bot commented Feb 8, 2025

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

Name Status Preview Comments Updated (UTC)
select ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 8, 2025 2:48am

Copy link
Contributor

coderabbitai bot commented Feb 8, 2025

Walkthrough

该 PR 对 rc-select 组件库进行了多项更新。主要工作包括:更新 package.json 中 rc-overflow 的版本;在 BaseSelect 和 OptionList 组件中添加 showScrollBar 属性;在 MultipleSelector 渲染函数中增加 index 参数,并更新相应接口(DisplayValueType 和 CustomTagProps);同时新增了测试用例和工具函数以验证滚动条和 tagRender 的行为,以及监控 Element 原型属性。

Changes

文件 变更说明
package.json 更新 rc-overflow 依赖版本(^1.3.1 → ^1.4.0)
src/BaseSelect/index.tsx, src/OptionList.tsx, src/Selector/MultipleSelector.tsx, src/interface.ts 为组件和接口新增 showScrollBar 属性及 index(CustomTagProps 和 DisplayValueType添加 index),并更新渲染函数签名
tests/ListScrollBar.test.tsx, tests/Tags.test.tsx 新增测试用例,验证滚动条显示和 tagRender 接收 index 属性
tests/utils/domHook.ts 新增 spyElementPrototypes 与 spyElementPrototype 工具函数,用于监控 Element 原型属性

Sequence Diagram(s)

sequenceDiagram
    participant S as Select组件
    participant MS as MultipleSelector
    participant CR as customizeRenderSelector
    participant TR as tagRender函数

    S->>MS: 调用 renderItem(value, { index })
    MS->>CR: 调用 customizeRenderSelector(..., info: { index })
    CR->>TR: 传递标签渲染信息(含 index)
    TR-->>CR: 返回渲染后的标签
    CR-->>MS: 返回渲染结果
Loading

Possibly related PRs

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.

src/OptionList.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[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/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)
src/BaseSelect/index.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[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/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)
tests/ListScrollBar.test.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[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/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)
  • 4 others
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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
Contributor

@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

🧹 Nitpick comments (3)
tests/utils/domHook.ts (1)

4-54: 实现得很好,但建议添加类型定义!

spyElementPrototypes 函数实现得很完整,包含了属性和方法的模拟以及清理功能。不过建议添加 TypeScript 类型定义以提高代码的可维护性。

建议添加以下类型定义:

+interface SpyProperty {
+  get?: (descriptor: PropertyDescriptor) => any;
+  set?: (descriptor: PropertyDescriptor, value: any) => void;
+}
+
+type SpyProperties = {
+  [key: string]: ((descriptor: PropertyDescriptor, ...args: any[]) => any) | SpyProperty;
+};
+
 export function spyElementPrototypes(
+  Element: typeof HTMLElement,
+  properties: SpyProperties
 ) {
tests/ListScrollBar.test.tsx (1)

70-84: 建议添加更多测试用例!

当前的测试用例验证了 showScrollBar 为 true 时的情况,建议添加以下测试场景:

  1. showScrollBar 为 false 时的情况
  2. 动态切换 showScrollBar 的情况
  3. 不同选项数量下的滚动条行为

示例测试用例:

it('should not show scrollbar when showScrollBar is false', async () => {
  const options = Array.from({ length: 10 }, (_, index) => ({
    label: `${index + 1}`,
    value: `${index + 1}`,
  }));

  const { container } = render(<Select open showScrollBar={false} options={options} />);

  await waitFor(() => {
    const scrollbarElement = container.querySelector('.rc-virtual-list-scrollbar-visible');
    expect(scrollbarElement).toBeNull();
  });
});

it('should toggle scrollbar visibility when showScrollBar changes', async () => {
  const options = Array.from({ length: 10 }, (_, index) => ({
    label: `${index + 1}`,
    value: `${index + 1}`,
  }));

  const { container, rerender } = render(<Select open showScrollBar options={options} />);

  // 首先验证滚动条可见
  await waitFor(() => {
    const scrollbarElement = container.querySelector('.rc-virtual-list-scrollbar-visible');
    expect(scrollbarElement).not.toBeNull();
  });

  // 重新渲染组件,关闭滚动条
  rerender(<Select open showScrollBar={false} options={options} />);

  // 验证滚动条不可见
  await waitFor(() => {
    const scrollbarElement = container.querySelector('.rc-virtual-list-scrollbar-visible');
    expect(scrollbarElement).toBeNull();
  });
});
src/Selector/MultipleSelector.tsx (1)

155-188: 建议优化代码实现!

当前实现在传递 info 参数时有一些冗余,可以通过以下方式优化:

  1. 使用对象解构来简化参数传递
  2. undefined 替换为更明确的空对象

建议按如下方式重构代码:

-  const renderItem = (valueItem: DisplayValueType, info: { index: number }) => {
+  const renderItem = (valueItem: DisplayValueType, { index }: { index: number }) => {
     const { disabled: itemDisabled, label, value } = valueItem;
     // ...
     return typeof tagRender === 'function'
       ? customizeRenderSelector(
           value,
           displayLabel,
           itemDisabled,
           closable,
           onClose,
-          undefined,
+          false,
-          info,
+          { index },
         )
       : defaultRenderSelector(valueItem, displayLabel, itemDisabled, closable, onClose);
   };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ff731d and 0990797.

📒 Files selected for processing (8)
  • package.json (1 hunks)
  • src/BaseSelect/index.tsx (4 hunks)
  • src/OptionList.tsx (2 hunks)
  • src/Selector/MultipleSelector.tsx (4 hunks)
  • src/interface.ts (1 hunks)
  • tests/ListScrollBar.test.tsx (1 hunks)
  • tests/Tags.test.tsx (2 hunks)
  • tests/utils/domHook.ts (1 hunks)
🔇 Additional comments (6)
src/interface.ts (1)

19-19: 代码变更看起来不错!

添加 index 可选属性到 DisplayValueType 接口是一个很好的改进,它为标签渲染提供了更多的上下文信息。

src/OptionList.tsx (1)

47-47: 新增 showScrollBar 属性以控制滚动条显示

该更改通过 useBaseProps 引入 showScrollBar 属性并将其传递给 List 组件,增强了滚动条的可见性控制。

Also applies to: 329-329

tests/Tags.test.tsx (1)

17-17: 新增 tagRender 索引属性的测试用例

测试用例验证了 tagRender 函数是否正确接收并使用了 index 属性。测试覆盖了多个标签的渲染场景,确保每个标签都能获得正确的索引值。

Also applies to: 305-324

src/BaseSelect/index.tsx (2)

71-71: 为 CustomTagProps 添加 index 属性

为标签渲染函数添加了索引信息,使得可以根据标签的位置实现更灵活的自定义渲染。


139-139: 实现滚动条显示控制功能

通过以下更改实现了滚动条显示的控制:

  1. 在 BaseSelectProps 中添加 showScrollBar 属性
  2. 设置默认值为 'optional'
  3. 将属性添加到 baseSelectContext 中

Also applies to: 226-226, 689-689

package.json (1)

56-56: 更新 rc-overflow 依赖版本

将 rc-overflow 依赖版本从 ^1.3.1 更新到 ^1.4.0,这是一个小版本更新,应该保持向后兼容性。

✅ Verification successful

🌐 Web query:

rc-overflow 1.4.0 的更新内容是什么?

💡 Result:

Based on the provided search results, there is no specific information available about **rc-overflow 1.4.0** updates in the indexed sources. The latest version mentioned in the results is **rc-overflow 1.4.1**, released approximately a month ago[7], but no detailed changelog for version **1.4.0** is provided in the given search data.

For accurate details about **rc-overflow 1.4.0**, you would need to consult its official repository or npm page directly, as none of the provided sources explicitly document this version's changes[4][7].

Citations:

- 1: https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases
- 2: https://detekt.dev/changelog/
- 3: https://developer.android.com/jetpack/androidx/releases/compose-foundation?hl=zh-cn
- 4: https://www.npmjs.com/package/rc-overflow?activeTab=versions
- 5: https://github.com/anvilco/spectaql/blob/main/CHANGELOG.md
- 6: https://gitee.com/react-native-oh-library/usage-docs
- 7: https://www.npmjs.com/package/rc-overflow
- 8: https://docs.mia-platform.eu/docs/microfrontend-composer/composer/changelog
- 9: https://v2.tauri.app/zh-cn/release/tauri/v1.0.3/
- 10: https://tdesign.tencent.com/mobile-vue/changelog

确认 rc-overflow 依赖更新无问题

  • 将 rc-overflow 依赖由 ^1.3.1 更新到 ^1.4.0 属于小版本升级,保持向后兼容性。
  • Web 查询结果中没有显示该版本的详细更新内容,因此建议可参考官方仓库或 npm 页面以获取更多信息,但现有更新本身风险较低。

@EmilyyyLiu EmilyyyLiu closed this Feb 8, 2025
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.

1 participant