Skip to content

Conversation

@LovePlayCode
Copy link

@LovePlayCode LovePlayCode commented Dec 25, 2025

解决52602 的问题,在 menu 组件中,如果传入了 extra,文字超长时无法显示省略号,因此进行了判断,如果发现有 extra,添加 span 标签包裹。

Summary by CodeRabbit

发布说明

  • Bug Fixes(错误修复)

    • 改进了菜单项中额外内容的渲染逻辑,确保包含额外信息的菜单项能够正确显示和布局。
  • UI/样式改进

    • 优化了菜单项标签和额外内容的条件渲染,提升了菜单组件的视觉表现。

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 25, 2025

概览

该变更在菜单项中引入 hasExtra 标志用于检测额外内容的存在,根据条件为项目标签添加专用包装 span,并将额外内容的渲染调整为仅在存在时渲染。

变更

内聚组 / 文件 变更摘要
菜单项标签和额外内容条件渲染
src/utils/nodeUtil.tsx
新增 hasExtra 标志检测逻辑;在额外内容存在时将标签包装在 ${prefixCls}-item-label span 中;将额外内容移入 ${prefixCls}-item-extra span 并添加存在性条件判断

估算代码审查工作量

🎯 2 (Simple) | ⏱️ ~10 分钟

可能相关的 PR

  • refactor: add extra pass #740 — 同样修改 src/utils/nodeUtil.tsx 中的菜单项 "extra" 处理逻辑,涉及 extra 的传递/渲染方式和 CSS 类名重命名至 -item-extra

建议审查者

  • zombieJ

🐰 菜单项穿上新衣裳,
标签与额外各自成对,
条件判断妙笔生花,
只在需时才展现光芒!✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰描述了主要改动:调整MenuItem的渲染逻辑,将label包装在span中,与raw_summary中的核心变更内容一致。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @LovePlayCode, 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!

此拉取请求旨在解决 Menu 组件中 MenuItem 文本在存在额外内容 (extra) 时无法正确显示省略号的问题。通过调整 MenuItem 的渲染逻辑,确保 label 文本在特定条件下被适当的 <span> 标签包裹,从而恢复了预期的文本截断行为,提升了用户界面的可读性和一致性。

Highlights

  • 修复菜单项文本省略问题: 当 MenuItem 包含 extra 内容时,其 label 文本现在会被一个 <span> 标签包裹,以确保文本超长时能正确显示省略号。
  • 优化条件判断: 引入 hasExtra 变量,统一并优化了 extra 属性存在的条件判断逻辑,使其更清晰和简洁。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

本次 PR 旨在解决 MenuItem 中当存在 extra 属性时,长文本 label 无法正常显示省略号的问题。您通过在 label 外包裹一层 span 标签来解决此问题,这是一个正确的方向。同时,您将判断 extra 是否存在的逻辑提取到了 hasExtra 变量中,优化了代码的可读性和条件判断,做得很好。我对代码进行了一处小优化建议,以进一步提升代码的简洁性。

return <MergedDivider key={mergedKey} {...restProps} />;
}

const hasExtra = !!extra || extra === 0;

Choose a reason for hiding this comment

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

medium

为了使代码更简洁,这里的条件判断可以省略 !!。在 JavaScript 的布尔运算中,extra 会被自动转换为布尔值进行判断,因此 !!extraextra 在此处的逻辑效果是等价的。

Suggested change
const hasExtra = !!extra || extra === 0;
const hasExtra = extra || extra === 0;

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/utils/nodeUtil.tsx (1)

52-55: 移除冗余的 extra prop 传递,仅通过 children 渲染

extra 属性通过 prop 传递给 MergedMenuItem,但 MenuItem 组件会显式忽略它(参见 MenuItem.tsx 中的 omit(restProps, ['extra']))。实际的 extra 内容仅通过 children 中的 span 元素渲染。建议只通过 children 方式传递 extra 内容,移除不必要的 prop 传递,以简化代码逻辑。

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3ae269 and ba7a389.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/MenuItem.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • src/utils/nodeUtil.tsx
🔇 Additional comments (1)
src/utils/nodeUtil.tsx (1)

50-50: hasExtra 逻辑正确处理了 0 值

这行代码正确地将 0 视为有效的 extra 值,符合预期行为。这样可以确保当 extra0 时,label 也会被包装在 span 中以支持文字省略。

Comment on lines +53 to +54
{hasExtra ? <span className={`${prefixCls}-item-label`}>{label}</span> : label}
{hasExtra && <span className={`${prefixCls}-item-extra`}>{extra}</span>}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

潜在问题:prefixCls 可能为 undefined 导致无效的 class 名称

prefixClsundefined 时(函数参数中标记为可选),模板字符串 `${prefixCls}-item-label` 会生成 "undefined-item-label" 这样的无效 class 名称。

建议添加保护逻辑:

🔎 建议的修复方案

方案一:添加默认值

-            {hasExtra ? <span className={`${prefixCls}-item-label`}>{label}</span> : label}
-            {hasExtra && <span className={`${prefixCls}-item-extra`}>{extra}</span>}
+            {hasExtra ? <span className={prefixCls ? `${prefixCls}-item-label` : 'item-label'}>{label}</span> : label}
+            {hasExtra && <span className={prefixCls ? `${prefixCls}-item-extra` : 'item-extra'}>{extra}</span>}

方案二:在函数开始处验证 prefixCls
convertItemsToNodes 函数中添加断言或默认值:

function convertItemsToNodes(
  list: ItemType[],
  components: Required<Components>,
  prefixCls: string = 'rc-menu', // 添加默认值
) {
  // ...
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{hasExtra ? <span className={`${prefixCls}-item-label`}>{label}</span> : label}
{hasExtra && <span className={`${prefixCls}-item-extra`}>{extra}</span>}
{hasExtra ? <span className={prefixCls ? `${prefixCls}-item-label` : 'item-label'}>{label}</span> : label}
{hasExtra && <span className={prefixCls ? `${prefixCls}-item-extra` : 'item-extra'}>{extra}</span>}
🤖 Prompt for AI Agents
In src/utils/nodeUtil.tsx around lines 53-54, the template strings using
prefixCls can produce invalid class names when prefixCls is undefined; ensure
prefixCls has a safe default or validate it at function entry (e.g., set
prefixCls = 'rc-menu' or assert/throw if missing) so subsequent
`${prefixCls}-item-label` and `${prefixCls}-item-extra` produce valid class
names; update the function signature or add an early guard to normalize
prefixCls before use.

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