Skip to content

Conversation

crazyair
Copy link
Contributor

@crazyair crazyair commented Sep 5, 2025

Summary by CodeRabbit

  • 新功能
    • 虚拟表格支持列最小宽度(minWidth),列宽计算更合理。
  • 变更
    • 横向滚动改用 scrollX 配置,替代样式对象方式。
  • 修复
    • 无列时不再渲染空表头结构,避免潜在渲染异常。
    • 设定宽度的列不再用标题参与宽度测量,减少错位。
  • 文档
    • 新增粘性表头与横向滚动示例,补充对齐问题说明与链接。
  • 样式
    • 移除单元格强制断词,遵循浏览器默认换行。
  • 杂项
    • 版本升级至 7.52.6。

Copy link

vercel bot commented Sep 5, 2025

@crazyair 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 bot commented Sep 5, 2025

Caution

Review failed

Failed to post review comments.

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 1cc47dc and 539ea5e.

⛔ Files ignored due to path filters (3)
  • tests/__snapshots__/ExpandRow.spec.jsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/FixedColumn.spec.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/Table.spec.jsx.snap is excluded by !**/*.snap
📒 Files selected for processing (9)
  • assets/index.less (0 hunks)
  • docs/examples/scrollY.tsx (1 hunks)
  • docs/examples/stickyHeader.tsx (5 hunks)
  • package.json (1 hunks)
  • src/Body/MeasureCell.tsx (1 hunks)
  • src/ColGroup.tsx (1 hunks)
  • src/FixedHolder/index.tsx (3 hunks)
  • src/Table.tsx (1 hunks)
  • src/VirtualTable/BodyGrid.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • assets/index.less
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-08T12:53:09.293Z
Learnt from: bbb169
PR: react-component/table#1202
File: src/Table.tsx:903-904
Timestamp: 2024-11-08T12:53:09.293Z
Learning: 在 `src/Table.tsx` 文件的 React 组件 `Table` 中,即使 `bodyScrollLeft` 频繁更新,也需要在 `TableContextValue` 的 `useMemo` 依赖数组中包含 `bodyScrollLeft` 和 `headerCellRefs`,因为每次滚动时重新计算 `TableContextValue` 是解决该问题所必须的。

Applied to files:

  • src/FixedHolder/index.tsx
  • docs/examples/scrollY.tsx
  • src/Table.tsx
  • docs/examples/stickyHeader.tsx
🧬 Code graph analysis (2)
docs/examples/scrollY.tsx (2)
tests/FixedColumn-IE.spec.jsx (1)
  • columns (28-41)
tests/Scroll.spec.jsx (1)
  • data (8-11)
docs/examples/stickyHeader.tsx (1)
src/interface.ts (1)
  • ColumnType (105-120)

Walkthrough

本次变更移除了表格单元格的断词样式;为文档示例新增/完善 sticky 与横向滚动示例;调整列宽测量逻辑;在虚拟表格中引入 minWidth 参与宽度计算;变更 FixedHolder 对横向滚动的传参接口(由 scrollTableStyle 改为 scrollX);修正空列组渲染;版本号小幅提升。

Changes

Cohort / File(s) Change Summary
样式调整
assets/index.less
删除 th, tdword-break: break-word 规则。
文档示例扩充(滚动与 sticky)
docs/examples/scrollY.tsx, docs/examples/stickyHeader.tsx
新增横向滚动 sticky 示例,补充演示数据与说明;在 scrollY 示例后追加第二个带 scroll={{ y:300, x:2000 }} 的表格及说明。
版本元数据
package.json
版本号从 7.52.5 升至 7.52.6
列宽测量
src/Body/MeasureCell.tsx
测量单元渲染从 column?.title 改为当存在 width 时使用空字符串,否则使用 title;默认回退为不换行空格。
ColGroup 渲染
src/ColGroup.tsx
当无列时返回 null,否则渲染 <colgroup>
固定表头/横向滚动 API
src/FixedHolder/index.tsx, src/Table.tsx
将 props 中的 scrollTableStyle 替换为 scrollX(`number
虚拟表格列宽计算
src/VirtualTable/BodyGrid.tsx
列宽采用 finalWidth = max(width, minWidth);相关偏移与回调基于 finalWidth

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Table as Table
  participant FixedHolder as FixedHolder (Header)
  participant Header as TableComponent (Header DOM)

  User->>Table: 渲染含横向滚动的表格
  Table->>FixedHolder: props { scrollX: mergedScrollX, ... }
  FixedHolder->>Header: 应用样式 { minWidth: 100%, width: scrollX }
  Header-->>User: 渲染固定表头(宽度受 scrollX 控制)
Loading
sequenceDiagram
  autonumber
  participant VT as VirtualTable
  participant BG as BodyGrid
  participant Col as Columns

  VT->>BG: 计算列布局
  loop 各列
    BG->>Col: 读取 width, minWidth
    BG-->>BG: finalWidth = max(width, minWidth)
    BG-->>VT: 返回 [key, finalWidth, total]
  end
  VT-->>VT: 基于 finalWidth 布局/滚动
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • zombieJ
  • afc163
  • MadCcc

Poem

小兔敲键不觉晚,
列宽量尺换新算。
横滚一指表头稳,
空组不渲不添乱。
版本轻跃点点欢,
「咔嗒」耳动心也安。 🐇✨

✨ 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

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

@crazyair crazyair changed the base branch from master to antd-5.x September 5, 2025 23:26
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.

Summary of Changes

Hello @crazyair, 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 significantly improves the handling of table column widths, particularly in scenarios involving horizontal scrolling and fixed headers. The changes ensure that column widths are calculated and applied more accurately, addressing layout inconsistencies and enhancing the overall table rendering experience. New examples have been added to validate these improvements against reported issues.

Highlights

  • Table Column Width Handling: Refactored the FixedHolder component to directly apply the scrollX property as the table's width, ensuring more accurate and consistent column width behavior, especially in tables with fixed headers and horizontal scrolling. This change also includes setting min-width: 100% for the table.
  • Column Measurement Accuracy: Modified MeasureCell to prevent rendering column titles when a column has an explicit width defined. This adjustment helps in more precise column width measurement and layout calculations.
  • Virtualized Table Column Widths: Enhanced the column width calculation logic within VirtualTable/BodyGrid.tsx to correctly account for both width and minWidth properties, improving the rendering of virtualized tables.
  • Conditional ColGroup Rendering: Updated ColGroup to conditionally render the <colgroup> element only when there are actual columns present, preventing the rendering of empty colgroup tags and streamlining the table's DOM structure.
  • New Examples and Issue References: Added new examples in docs/examples/scrollY.tsx and docs/examples/stickyHeader.tsx to demonstrate and test specific column alignment and scroll.x behaviors, referencing related GitHub issues (#54889 and #54894).
  • CSS Styling Adjustment: Removed the word-break: break-word; CSS property from table cells in assets/index.less, which may affect text wrapping behavior within columns.
  • Version Bump: The package version has been incremented from 7.52.5 to 7.52.6 in package.json.
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
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 attempts to optimize column width measurement by avoiding rendering the title when a width is already specified. However, this change introduces a critical bug in src/Body/MeasureCell.tsx that could lead to a runtime error. The code does not check if the column prop is defined before using the in operator, which will throw a TypeError if column is undefined. I have provided a fix for this issue.

>
<div style={{ height: 0, overflow: 'hidden', fontWeight: 'bold' }}>
{column?.title || '\xa0'}
{('width' in column ? '' : column?.title) || '\xa0'}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The column prop is optional and can be undefined. Using the in operator on an undefined value will cause a TypeError at runtime. You should add a null check for column before attempting to access its properties or use the in operator.

Suggested change
{('width' in column ? '' : column?.title) || '\xa0'}
{(column && 'width' in column ? '' : column?.title) || '\xa0'}

@afc163
Copy link
Member

afc163 commented Sep 6, 2025

有问题重现么

@crazyair
Copy link
Contributor Author

crazyair commented Sep 6, 2025

有问题重现么

这个改了demo,你验证那个demo是否可用

>
<div style={{ height: 0, overflow: 'hidden', fontWeight: 'bold' }}>
{column?.title || '\xa0'}
{('width' in column ? '' : column?.title) || '\xa0'}
Copy link
Member

Choose a reason for hiding this comment

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

这样修好像没效果。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

就是如果传了 width,就不渲染 title 了,还用空占位

Copy link
Member

Choose a reason for hiding this comment

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

没效果,还是 width: auto 的问题,去掉就好了。之前 scroll={{ x: true }} 时默认设置的就是 width: auto,现在可以考虑去掉了。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

也可能吧,我调试的时候,宽度一直不生效,还以为确实有问题,所以才改的。其实是列太多,导致 width 200 本来就会被挤掉的吧

@crazyair crazyair closed this Sep 6, 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.

2 participants