Skip to content

fix: do not render scrollbar column when table is empty#1477

Open
hblab-tiennm wants to merge 2 commits intoreact-component:masterfrom
hblab-tiennm:fix/no-scrollbar-column-when-empty
Open

fix: do not render scrollbar column when table is empty#1477
hblab-tiennm wants to merge 2 commits intoreact-component:masterfrom
hblab-tiennm:fix/no-scrollbar-column-when-empty

Conversation

@hblab-tiennm
Copy link
Copy Markdown

@hblab-tiennm hblab-tiennm commented Apr 16, 2026

Chinese template / 中文版模板

This is a ...

  • Bug fix

Related Issues

  • Reproduces in antd@5.29.3 with scroll.y enabled and empty data.

Background and Solution

When scroll.y is enabled, FixedHolder always appends ScrollBarColumn to header columns when combinationScrollBarSize is truthy.

In empty state, the table body renders the placeholder row instead of a scrollable body, so the extra scrollbar placeholder column is not needed. Keeping it in the header causes an extra rc-table-cell-scrollbar header cell to be rendered.

This change skips appending ScrollBarColumn when noData is true, and adds a regression test to cover the empty-state case.

Changelog

Language Changelog
🇺🇸 English Fix Table rendering an extra scrollbar header cell when scroll.y is enabled and data is empty.
🇨🇳 Chinese 修复 Table 在启用 scroll.y 且数据为空时,表头额外渲染 scrollbar 占位列的问题。

Summary by CodeRabbit

  • Bug Fixes

    • 修复了表格数据为空时仍显示滚动条列的问题:当无数据时自动隐藏滚动条列,改善固定列表格的显示与体验。
  • Tests

    • 新增单元测试,验证在空数据且开启横纵滚动时不渲染滚动条表头并保留占位符,用以防止回归。

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 16, 2026

@hblab-tiennm is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d28ae115-b66a-40e4-93e1-ba9db2daf779

📥 Commits

Reviewing files that changed from the base of the PR and between d4d1b62 and ca3af2e.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/FixedColumn.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • src/FixedHolder/index.tsx

Walkthrough

FixedHolder 中引入 shouldAppendScrollBarColumn(结合 combinationScrollBarSize!noData)以在无数据时避免追加滚动条列;同时更新相关 memo 和粘性偏移计算。新增测试覆盖无数据且启用滚动的行为断言。

Changes

Cohort / File(s) Summary
FixedHolder 滚动条条件与偏移
src/FixedHolder/index.tsx
新增 shouldAppendScrollBarColumn = combinationScrollBarSize && !noData,将 columnsWithScrollbarflattenColumnsWithScrollbar 改为基于该条件追加 ScrollBarColumn,并使 end 粘性偏移使用基于该条件的 scrollbarOffset
无数据场景测试
tests/FixedColumn.spec.tsx
新增用例:在空数据且 scroll={{ x: 1200, y: 100 }} 的情况下触发 resize,断言不渲染滚动条头单元格且占位符存在。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 分钟

Possibly related PRs

Suggested reviewers

  • afc163
  • zombieJ

兔子的庆祝诗

🐰 小兔说:滚动条学会分寸,
无数据时静静不露身,
测试轻敲边界心安定,
代码更稳功能更真,
胡萝卜庆祝一口吞🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确总结了主要改动:当表格无数据时不渲染滚动条列。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown
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 modifies the table header logic to prevent the scrollbar column from being appended when the table is empty. A new test case and updated snapshots were added to verify this behavior. However, feedback indicates that the implementation is incomplete because the sticky offset calculations for fixed columns still account for the scrollbar width even when it is not rendered, resulting in layout gaps in the empty state.

Comment thread src/FixedHolder/index.tsx
className: `${prefixCls}-cell-scrollbar`,
}),
};
const shouldAppendScrollBarColumn = combinationScrollBarSize && !noData;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While this change correctly prevents the scrollbar column from being appended to the header when the table is empty, it is incomplete. The headerStickyOffsets calculation (around line 156) still uses combinationScrollBarSize directly, which means fixed columns will still have sticky offsets that account for a non-existent scrollbar. This leads to an incorrect layout gap in the empty state, as seen in the updated snapshots (e.g., inset-inline-end: 15px remaining despite the column removal). You should also update the headerStickyOffsets logic to use shouldAppendScrollBarColumn instead of combinationScrollBarSize.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. This finding was valid.

I updated headerStickyOffsets to use the same shouldAppendScrollBarColumn condition, so the scrollbar width is only included when the scrollbar placeholder column is actually appended.

This was pushed in ca3af2e, and I re-ran pnpm test tests/FixedColumn.spec.tsx -u to verify the empty-state fixed-column layout stays in sync.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/FixedHolder/index.tsx`:
- Around line 134-143: The header sticky offset calculation is unconditionally
adding the scrollbar width even when noData prevents appending ScrollBarColumn,
causing misaligned fixed columns; update the headerStickyOffsets computation to
use the same shouldAppendScrollBarColumn condition (the same boolean used for
columnsWithScrollbar and flattenColumnsWithScrollbar) so the scrollbar width is
only included in headerStickyOffsets when shouldAppendScrollBarColumn is true
(reference shouldAppendScrollBarColumn, columnsWithScrollbar,
flattenColumnsWithScrollbar, headerStickyOffsets).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7cddf4c1-8ffc-44ca-9478-1d28cfff3dfa

📥 Commits

Reviewing files that changed from the base of the PR and between 29dcc3e and d4d1b62.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/FixedColumn.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/FixedHolder/index.tsx
  • tests/FixedColumn.spec.tsx

Comment thread src/FixedHolder/index.tsx
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