Skip to content

Fix fixed property not being inherited by children columns #1303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ryantang247
Copy link

@ryantang247 ryantang247 commented Jul 16, 2025

Fixes https://github.com/ant-design/ant-design/issues/51812

Similar issue: https://table-react-component.vercel.app/demo/fixed-columns-and-header-rtl

fixedColumnsAndHeaderRtl

Applying to Fix Left and Fix title3 should make the parent column fixed as well as the children.

Due to misordering of the properties of the column, the fixed property isn't inherited from the parent due to property overriding from object spread.

Summary by CodeRabbit

  • 修复问题
    • 修复了嵌套列固定属性的继承问题,子列现在会优先保留自身的固定设置,只有在未设置时才继承父列的固定属性。

Copy link

vercel bot commented Jul 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
table ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 16, 2025 9:00am

Copy link

coderabbitai bot commented Jul 16, 2025

Walkthrough

本次更改调整了 flatColumns 函数在处理嵌套列时的逻辑。现在,子列的 fixed 属性如果已定义则保留,否则继承父列的 fixed 属性,不再无条件覆盖子列的设置。

Changes

文件/文件组 变更摘要
src/hooks/useColumns/index.tsx 优化 flatColumns,子列优先保留自身 fixed 属性,否则继承父列。

Sequence Diagram(s)

sequenceDiagram
    participant 调用者
    participant flatColumns
    participant 子列

    调用者->>flatColumns: 传入 columns
    flatColumns->>flatColumns: 遍历每个 column
    alt column 有 children
        flatColumns->>子列: 检查子列 fixed 属性
        alt 子列有 fixed
            flatColumns->>子列: 保留子列 fixed
        else
            flatColumns->>子列: 继承父列 fixed
        end
    end
    flatColumns-->>调用者: 返回扁平化后的 columns
Loading

Assessment against linked issues

Objective Addressed Explanation
子列有 children 时,能够正确固定在右侧(#51812)

Suggested reviewers

  • zombieJ
  • afc163

Poem

小兔敲键盘,列固定真欢喜,
父子属性巧传递,灵活不失仪。
右侧固定没烦恼,表头分组乐淘淘。
🐰✨代码如春风,体验步步高!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/hooks/useColumns/index.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

✨ 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

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

Documentation and Community

  • 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

@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)
src/hooks/useColumns/index.tsx (1)

74-74: 变量名拼写错误。

变量名 subColum 应该是 subColumn(缺少字母 'n')。

建议修复拼写错误:

-          ...flatColumns(subColumns, mergedKey).map(subColum => ({
+          ...flatColumns(subColumns, mergedKey).map(subColumn => ({

对应地,第76行也需要修改:

-            fixed: subColum.fixed ?? parsedFixed,
+            fixed: subColumn.fixed ?? parsedFixed,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57579f1 and e9e3847.

📒 Files selected for processing (1)
  • src/hooks/useColumns/index.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
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` 是解决该问题所必须的。
src/hooks/useColumns/index.tsx (1)
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` 是解决该问题所必须的。
🔇 Additional comments (1)
src/hooks/useColumns/index.tsx (1)

74-77: 逻辑修复正确,很好地解决了固定属性继承问题。

这个修改正确地解决了子列固定属性不被父列覆盖的问题。使用空值合并运算符 ?? 确保:

  • 如果子列已经定义了 fixed 属性,则保留其值
  • 如果子列没有定义 fixed 属性,则继承父列的 parsedFixed

这样既保持了向后兼容性,又修复了属性继承的逻辑错误。

Copy link

codecov bot commented Jul 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.71%. Comparing base (57579f1) to head (e9e3847).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1303   +/-   ##
=======================================
  Coverage   95.71%   95.71%           
=======================================
  Files          57       57           
  Lines        3410     3410           
  Branches      660      661    +1     
=======================================
  Hits         3264     3264           
  Misses        121      121           
  Partials       25       25           

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

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