Skip to content

Conversation

coding-ice
Copy link

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

Summary by CodeRabbit

  • 新功能

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

    • 组件接口移除单一的 style 与 className,需迁移到基于 SemanticName 的 styles 与 classNames(新增 'close' 语义键),影响 TabNode、OperationNode 与上层调用处。
  • 测试

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

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

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 / close / ...
  loop 每个 tab
    Nav->>Node: render({ classNames: {item, close}, styles: {item, close}, ... })
    Node->>Node: 使用 classNames?.item / styles?.item 构建 DOM
    alt 标签可编辑且有 close
      Node->>Node: 使用 classNames?.close / styles?.close 渲染关闭按钮
    end
  end
  Nav->>Op: 下拉操作菜单传入 classNames?.close / styles?.close
  Op->>Op: 下拉中的移除按钮应用 close 语义的类与样式
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • zombieJ

Poem

我在代码地里轻轻跳,🐰
把 style 分成篮子按语义放,
item 穿整齐,close 戴小帽,
classNames 与 styles 并排跑,
关闭按钮也有了专属小道。

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive PR 标题“feat: add a close button element for semantic”与新增 'close' 语义名称并支持对应样式/类名的改动部分相关,但用词略显模糊且未清晰传达同时重构 style/className 到 styles/classNames 的整体变更范围。 建议将标题修改为更明确且简洁的描述,例如 “feat: add 'close' 语义名称并更新样式和 classNames API”,以便同事一眼理解主要变更内容。
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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

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 (1b20c6f).
⚠️ 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      234    -3     
=======================================
  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.

coding-ice and others added 2 commits October 9, 2025 21:28
Co-authored-by: lijianan <574980606@qq.com>
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 评论。

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