Skip to content

Conversation

coding-ice
Copy link

@coding-ice coding-ice commented Sep 24, 2025

Summary by CodeRabbit

  • 新功能

    • 支持按语义键(如 item 与 close)为标签项与关闭按钮分别配置 styles 与 classNames,便于更细粒度样式定制,覆盖标签列表、操作菜单与溢出项。
  • 破坏性变更

    • 组件接口不再使用单一 style 与 className,需迁移到基于语义键的 styles 与 classNames(新增 close 语义键)。
  • 测试

    • 新增用例验证可编辑标签的关闭按钮在直接渲染与溢出菜单中均接受自定义类名与样式。

Copy link

coderabbitai bot commented Sep 24, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

将 Tab 组件的样式/类名 API 从单一的 style/className 重构为按语义键的 styles/classNames 映射,新增语义键 remove;更新 TabNavListTabNodeOperationNode 的 props 与调用,新增测试覆盖移除(关闭)按钮的类名与样式。

Changes

Cohort / File(s) Summary
样式 API 语义化重构(TabNode)
src/TabNavList/TabNode.tsx
style?: React.CSSPropertiesclassName?: string 替换为 styles?: Pick<Partial<Record<SemanticName, React.CSSProperties>>, 'item' | 'remove'>classNames?: Pick<Partial<Record<SemanticName, string>>, 'item' | 'remove'>;使用 stylesclassNames(本地别名 tabNodeClassNames)解构并在 DOM 上使用 styles?.item/tabNodeClassNames?.item 与移除按钮的 styles?.remove/tabNodeClassNames?.remove;增加 SemanticName 类型导入。
样式传递更新(TabNavList 渲染逻辑)
src/TabNavList/index.tsx
渲染 TabNode 时改为传入按语义的 classNamesstyles 映射(包含 itemremove),保持首个 tab 的 item 合并逻辑但通过新的映射传递,显式为移除按钮提供 remove 语义的类名与样式。
类型扩展(SemanticName 增加 remove)
src/Tabs.tsx
扩展导出类型 SemanticName,新增 'remove',以支持对移除按钮的按语义 className/style 映射。
下拉操作节点样式支持(OperationNode)
src/TabNavList/OperationNode.tsx
OperationNode 添加 stylesclassNames props,且在下拉菜单的移除项上使用 classNames?.removestyles?.remove;导入并使用 SemanticName 类型。
测试(移除按钮样式/类名)
tests/index.test.tsx, tests/overflow.test.tsx
新增测试用例验证可编辑 Tabs 的移除按钮(标签与下拉中的移除项)能接收并应用自定义 classNames.removestyles.remove(断言类名与内联样式)。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App as 应用
  participant Tabs as Tabs
  participant Nav as TabNavList
  participant Node as TabNode
  participant Op as OperationNode

  App->>Tabs: 传入 props (classNames, styles, ...)
  Tabs->>Nav: 转发列表与语义化样式映射
  Note over Tabs,Nav: 语义键包含 item / remove / ...
  loop 每个 tab
    Nav->>Node: render({ classNames: {item, remove}, styles: {item, remove}, ... })
    Node->>Node: 使用 classNames?.item / styles?.item 构建 DOM
    alt 标签可编辑且有 remove
      Node->>Node: 使用 classNames?.remove / styles?.remove 渲染移除按钮
    end
  end
  Nav->>Op: 下拉操作菜单传入 classNames?.remove / styles?.remove
  Op->>Op: 下拉中的移除项应用 remove 语义的类与样式
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • zombieJ

Poem

我在代码地里轻轻跳,🐰
把 style 分成语义的篮子放,
item 穿样式,remove 戴徽章,
classNames 与 styles 并排跑,
关闭(移除)按钮也有专属方向。

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题简洁地表达了此次 PR 主要引入了对“移除按钮”语义元素的支持,与更改中针对 TabNode、OperationNode 等组件新增 remove 语义样式和类名的修改保持一致。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 1b20c6f and 77c6040.

📒 Files selected for processing (6)
  • src/TabNavList/OperationNode.tsx (4 hunks)
  • src/TabNavList/TabNode.tsx (5 hunks)
  • src/TabNavList/index.tsx (1 hunks)
  • src/Tabs.tsx (1 hunks)
  • tests/index.test.tsx (1 hunks)
  • tests/overflow.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/index.test.tsx
  • src/TabNavList/index.tsx
🧰 Additional context used
🧬 Code graph analysis (3)
tests/overflow.test.tsx (1)
tests/common/util.tsx (2)
  • getTabs (113-147)
  • triggerResize (149-156)
src/TabNavList/TabNode.tsx (1)
src/Tabs.tsx (1)
  • SemanticName (38-38)
src/TabNavList/OperationNode.tsx (1)
src/Tabs.tsx (1)
  • SemanticName (38-38)
🔇 Additional comments (7)
src/Tabs.tsx (1)

38-38: LGTM! 语义类型扩展合理

正确地将 'remove' 添加到 SemanticName 联合类型中,为移除按钮提供了独立的样式语义支持。这与 TabNode 和 OperationNode 中的使用保持一致。

src/TabNavList/TabNode.tsx (3)

27-28: LGTM! 类型定义正确解决了之前的问题

现在使用 Pick<Partial<Record<SemanticName, ...>>, 'item' | 'remove'> 正确地允许可选的语义键,解决了之前评审中提到的类型过严的问题。调用方可以选择性地提供 itemremove 的样式和类名。


87-93: LGTM! 语义化样式应用正确

正确地通过 tabNodeClassNames?.itemstyles?.item 应用 item 语义的类名和样式,可选访问符确保了类型安全。


134-135: LGTM! 移除按钮的语义样式应用正确

正确地为移除按钮应用了 remove 语义的类名和样式,与 item 的处理方式保持一致。

src/TabNavList/OperationNode.tsx (2)

31-32: LGTM! 弹出层移除按钮的语义支持已补充

正确地为下拉菜单中的移除按钮添加了 remove 语义的样式和类名支持,类型定义与 TabNode 保持一致。这解决了 PR 讨论中提到的"弹出层漏下了"的问题。


106-107: LGTM! 下拉菜单移除按钮正确应用了语义样式

下拉菜单中的移除按钮现在正确地应用了 classNames?.removestyles?.remove,与 TabNode 中的移除按钮使用相同的 remove 语义。这回答了 PR 讨论中关于"两个 close 按钮是否使用同一个语义"的问题——它们确实使用了统一的 remove 语义。

tests/overflow.test.tsx (1)

531-556: LGTM! 测试覆盖完整

新增的测试用例正确验证了下拉菜单中移除按钮的自定义类名和样式功能。测试流程清晰:

  1. 渲染带有自定义 remove 语义样式的可编辑标签页
  2. 触发下拉菜单显示
  3. 验证下拉菜单项的移除按钮正确应用了自定义类名和样式

测试覆盖了 OperationNode 的场景,与代码变更相符。


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.

Copy link

vercel bot commented Sep 24, 2025

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

Project Deployment Preview Comments Updated (UTC)
tabs Ready Ready Preview Comment Sep 30, 2025 2:04am

Copy link
Contributor

Summary of Changes

Hello @coding-ice, 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 customization capabilities for tab components by introducing a dedicated semantic name for the close button. It refactors the styling and class name props within the TabNode component to accept structured objects, allowing developers to apply distinct styles and classes to both the tab item and its close button. This change provides greater flexibility and control over the visual presentation of tabs.

Highlights

  • New 'close' Semantic Name: A new semantic name, 'close', has been introduced to the SemanticName type, allowing for more granular styling and class management of tab close buttons.
  • Refactored TabNode Styling Props: The TabNode component's style and className props have been replaced with styles and classNames objects. These new props now accept item and close keys, enabling distinct styling for the tab item itself and its close button.
  • Updated TabNavList Prop Passing: The TabNavList component has been updated to pass the new structured styles and classNames objects down to the TabNode component, ensuring the new styling mechanism is utilized.
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
Contributor

@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

This pull request adds the ability to style the close button on tabs by introducing a 'close' semantic name. The implementation is well-done and consistent. My main feedback is the lack of updated tests. The new functionality for classNames.close and styles.close should be covered by unit tests to prevent future regressions. I've also left one minor suggestion to improve type consistency.

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/TabNavList/index.tsx (1)

438-447: 按语义传递 item/close 的类名与样式 — LGTM;可微调合并以更健壮

在严格类型设置下(如 exactOptionalPropertyTypes),展开 styles?.item 可能触发类型告警。可使用空对象兜底,提升健壮性(行为不变)。

-          item: i === 0 ? styles?.item : { ...tabNodeStyle, ...styles?.item },
+          item: i === 0 ? styles?.item : { ...tabNodeStyle, ...(styles?.item || {}) },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c5dbbb and 8c4f5fd.

📒 Files selected for processing (3)
  • src/TabNavList/TabNode.tsx (5 hunks)
  • src/TabNavList/index.tsx (1 hunks)
  • src/Tabs.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/TabNavList/TabNode.tsx (1)
src/Tabs.tsx (1)
  • SemanticName (37-37)
🔇 Additional comments (7)
src/Tabs.tsx (1)

37-37: 扩展 SemanticName 包含 'close' — LGTM

与下游 TabNode/TabNavList 改动一致。

src/TabNavList/TabNode.tsx (3)

87-94: 为 item 节点应用语义化类名与样式 — LGTM

tabNodeClassNames?.itemstyles?.item 的解构与落点正确。


134-136: 为 close 按钮应用语义化类名与样式 — LGTM

tabNodeClassNames?.closestyles?.close 使用恰当。


5-5: 改为相对导入或确认 '@' 路径别名已配置

仓库搜索仅在 src/TabNavList/TabNode.tsx:5 发现 '@/Tabs' 引用,未找到 tsconfig 的 paths 或其它别名声明;建议改为相对导入以保持一致性:

-import type { SemanticName } from '@/Tabs';
+import type { SemanticName } from '../Tabs';

若需保留 '@' 别名,确认在 tsconfig.json 或构建配置(vite/webpack)中添加 "@/": ["src/"] 并确保构建/类型检查能解析该别名。

src/TabNavList/index.tsx (3)

593-595: header 语义的 className/style 透传 — LGTM

顺序为用户 style 覆盖语义 header,优先级合理。


633-637: indicator 语义的 className/style 透传 — LGTM

indicatorStyle 与自定义样式合并顺序合理。


650-651: 确认:OperationNode 已声明并使用 popupStyle,可直接传入

src/TabNavList/OperationNode.tsx 声明了 popupStyle?: React.CSSProperties(约第29行),并在下拉中以 overlayStyle={popupStyle} 使用(约第198行),因此在 src/TabNavList/index.tsx 传入 popupStyle={styles?.popup} 是安全的。

Copy link

codecov bot commented Sep 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.98%. Comparing base (5a33ccf) to head (77c6040).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #900   +/-   ##
=======================================
  Coverage   98.98%   98.98%           
=======================================
  Files          18       18           
  Lines         789      789           
  Branches      237      237           
=======================================
  Hits          781      781           
  Misses          8        8           

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

@li-jia-nan
Copy link
Member

close 按钮有两个,好像漏了一个地方

@coding-ice coding-ice changed the title feat: add 'close' semantic name and update TabNode styles and classNames feat: add a close button element for semantic Oct 9, 2025
@coding-ice
Copy link
Author

close 按钮有两个,好像漏了一个地方

弹出层的确实漏下了,我补一下~

@li-jia-nan
Copy link
Member

close 按钮有两个,好像漏了一个地方

弹出层的确实漏下了,我补一下~

我不确定这两个地方的 close 是不是要用同一个语义,可以问问 @zombieJ

Copy link

vercel bot commented Oct 9, 2025

@coding-ice is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

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 (1)
tests/index.test.tsx (1)

779-807: 简化测试设置以提高清晰度。

测试逻辑正确,但设置可能过于复杂。使用窄容器(100px)和 10 个标签项通常会触发溢出行为,但此测试仅检查可见标签的关闭按钮(.rc-tabs-tab-remove),而不是溢出下拉菜单中的按钮。

建议简化测试设置,使用较少的标签项和正常容器宽度,因为此测试的重点是可见标签的关闭按钮样式,而不是溢出行为。

可以考虑应用以下简化:

  it('support classnames and styles for editable close button', () => {
    const customClassNames = {
      close: 'custom-close',
    };
    const customStyles = {
      close: { background: 'red' },
    };

    const { container } = render(
-      <div style={{ width: 100 }}>
-        <Tabs
-          editable={{
-            onEdit: () => {},
-          }}
-          tabPosition="left"
-          items={Array.from({ length: 10 }).map((_, index) => ({
-            key: `test-${index}`,
-            label: `test-${index}`,
-            icon: 'test',
-          }))}
-          styles={customStyles}
-          classNames={customClassNames}
-        />
-      </div>,
+      <Tabs
+        editable={{
+          onEdit: () => {},
+        }}
+        items={[
+          { key: 'test-1', label: 'test-1', icon: 'test' },
+          { key: 'test-2', label: 'test-2', icon: 'test' },
+        ]}
+        styles={customStyles}
+        classNames={customClassNames}
+      />,
    );

    expect(container.querySelector('.rc-tabs-tab-remove')).toHaveClass('custom-close');
    expect(container.querySelector('.rc-tabs-tab-remove')).toHaveStyle({ background: 'red' });
  });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e64d138 and 1b20c6f.

📒 Files selected for processing (2)
  • tests/index.test.tsx (1 hunks)
  • tests/overflow.test.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/overflow.test.tsx (1)
tests/common/util.tsx (2)
  • getTabs (113-147)
  • triggerResize (149-156)
🔇 Additional comments (1)
tests/overflow.test.tsx (1)

531-556: 测试实现正确,补充了溢出下拉菜单的关闭按钮样式测试。

此测试正确地验证了溢出下拉菜单中关闭按钮的自定义样式和类名应用。测试流程清晰:

  1. 设置可编辑标签和自定义样式
  2. 触发溢出行为
  3. 打开下拉菜单
  4. 验证下拉菜单中的关闭按钮应用了自定义样式

这正是 PR 评论中提到的"弹出层"部分,与 tests/index.test.tsx 中的测试互补,共同覆盖了两种场景下的关闭按钮样式。

基于 PR 评论。

aria-label={removeAriaLabel || 'remove'}
tabIndex={0}
className={`${dropdownPrefix}-menu-item-remove`}
className={clsx(`${dropdownPrefix}-menu-item-remove`, classNames?.close)}
Copy link
Author

Choose a reason for hiding this comment

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

这里的 close 语义,不太确定是不是要改为 popup.close

@coding-ice coding-ice changed the title feat: add a close button element for semantic feat: add a remove button element for semantic Oct 13, 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.

3 participants