Skip to content

Conversation

EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Sep 2, 2025

相关issue:ant-design/ant-design#54839
Panel 支持使用optionRender自定义渲染选项

Summary by CodeRabbit

  • 新功能

    • Panel 组件新增 optionRender 属性,支持自定义选项渲染;该配置向下传递至子组件,变更后可即时生效。
  • 测试

    • 新增针对 Panel 中 optionRender 的单元测试,覆盖普通与禁用选项的渲染结果与动态更新。

Copy link

vercel bot commented Sep 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
cascader Error Error Sep 2, 2025 7:43am

Copy link

coderabbitai bot commented Sep 2, 2025

Walkthrough

在 Panel 组件中新增公开属性 optionRender,并通过 CascaderContext 向下传递;相应更新了类型定义与 useMemo 依赖。新增测试覆盖 Panel 的 optionRender 渲染行为与动态变更。

Changes

Cohort / File(s) Summary of changes
Panel API update
src/Panel.tsx
扩展 PickType,令 PanelProps 包含 optionRender;在组件中解构该属性并注入 CascaderContext.Provider;更新 useMemo 依赖以包含 optionRender
Tests for optionRender
tests/Panel.spec.tsx
新增用例“Should optionRender work in Panel”:验证自定义渲染文本与包含 disabled 的选项对象序列化渲染;通过 rerender 验证动态更新。

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Panel as Panel
    participant Ctx as CascaderContext
    participant Menu as Menu/OptionItem

    User->>Panel: render with { optionRender }
    Panel->>Ctx: provide { ... , optionRender }
    Ctx-->>Menu: consume optionRender
    Menu->>Menu: optionRender(option) -> ReactNode
    Menu-->>User: display customized option content

    note over Panel,Ctx: 当 optionRender 变化时,useMemo 促使上下文更新
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • zombieJ

Poem

兔子挥笔点点云,
面板添上渲染纹。
optionRender轻轻递,
上下文里顺畅巡。
菜单一笑样子新,
竹影涟涟映我心。

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @EmilyyyLiu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Panel component by adding a new optionRender prop. This feature provides users with the ability to customize the visual representation of individual options, significantly increasing the component's flexibility and adaptability to diverse UI design requirements.

Highlights

  • New Feature: Custom Option Rendering: Introduced an optionRender prop to the Panel component, allowing developers to provide a custom function for rendering individual options within the panel.
  • Type Definition and Prop Integration: Updated the PickType definition in src/Panel.tsx to include optionRender and integrated the prop into the component's internal logic and memoization dependencies.
  • Comprehensive Test Coverage: Added a new test case in tests/Panel.spec.tsx to thoroughly validate the functionality of the optionRender prop, ensuring it correctly customizes option display, including for disabled options.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

你好,感谢你的贡献!这次的 Pull Request 为 Panel 组件增加了 optionRender 功能,使得选项的渲染可以自定义,这非常有用。代码改动清晰、简洁,并且遵循了项目现有的模式,通过 CascaderContext 来传递 optionRender 属性。同时,你还添加了相应的单元测试来验证新功能的正确性,测试用例覆盖了基本场景和 rerender 的情况,保证了代码的质量。整体来看,这是一个高质量的提交,我没有发现任何问题。做得很好!

Copy link

codecov bot commented Sep 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.83%. Comparing base (3176b77) to head (00bd844).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #618   +/-   ##
=======================================
  Coverage   99.83%   99.83%           
=======================================
  Files          23       23           
  Lines         612      612           
  Branches      186      186           
=======================================
  Hits          611      611           
  Misses          1        1           

☔ 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.

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

🧹 Nitpick comments (2)
src/Panel.tsx (1)

164-165: 添加尾随逗号

       popupMenuColumnStyle: undefined,
-      optionRender
+      optionRender,
tests/Panel.spec.tsx (1)

114-133: 断言更稳健与命名一致性:使用 textContent,测试名与文件风格保持统一;另建议补一例仅变更 optionRender 的重渲染

  • 建议用 textContent 避免与潜在的 HTML 结构/转义耦合。
  • 测试名可与本文件其余用例风格统一(如 “optionRender in Panel”)。

可微调如下:

-  it('Should optionRender work in Panel', () => {
+  it('optionRender in Panel', () => {
@@
-    expect(container.querySelector('.rc-cascader-menu-item-content')?.innerHTML).toEqual(
+    expect(container.querySelector('.rc-cascader-menu-item-content')?.textContent).toEqual(
       'bamboo - test',
     );
@@
-    expect(container.querySelector('.rc-cascader-menu-item-content')?.innerHTML).toEqual(
+    expect(container.querySelector('.rc-cascader-menu-item-content')?.textContent).toEqual(
       '{"label":"bamboo","disabled":true,"value":"bamboo"}',
     );

另外可新增一例仅替换 optionRender(不改 options),以验证依赖项变更触发渲染更新:

it('optionRender update only', () => {
  const { container, rerender } = render(
    <Cascader.Panel options={[{ label: 'bamboo', value: 'bamboo' }]} optionRender={o => o.label} />,
  );
  expect(container.querySelector('.rc-cascader-menu-item-content')?.textContent).toEqual('bamboo');
  rerender(
    <Cascader.Panel options={[{ label: 'bamboo', value: 'bamboo' }]} optionRender={o => `${o.label}-x`} />,
  );
  expect(container.querySelector('.rc-cascader-menu-item-content')?.textContent).toEqual('bamboo-x');
});
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3176b77 and 00bd844.

📒 Files selected for processing (2)
  • src/Panel.tsx (4 hunks)
  • tests/Panel.spec.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test / react component workflow
🔇 Additional comments (3)
src/Panel.tsx (3)

39-41: 将 disabled 与 optionRender 纳入 Panel 的公开类型,修正类型缺口并公开新能力

这同步了 Panel 实际支持的 props(此前测试已使用 disabled)与类型定义,方向正确。建议在变更说明/文档中补充 “Panel 现支持 disabled 与 optionRender” 以避免使用者遗漏。


74-74: 解构新增 optionRender 合理

与下文 Context 透传保持一致,无其他问题。


178-179: useMemo 依赖补齐 optionRender

确保自定义渲染变更时及时触发重算,👍。

@zombieJ zombieJ merged commit 57a1793 into react-component:master Sep 2, 2025
10 of 11 checks passed
@EmilyyyLiu EmilyyyLiu deleted the optionRender-panel branch September 2, 2025 09:56
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