Skip to content

feat: support expand all control in expandable column header - #1505

Open
nikzanda wants to merge 5 commits into
react-component:masterfrom
nikzanda:feat/expand-all-header
Open

feat: support expand all control in expandable column header#1505
nikzanda wants to merge 5 commits into
react-component:masterfrom
nikzanda:feat/expand-all-header

Conversation

@nikzanda

@nikzanda nikzanda commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an opt-in expand/collapse-all control to the expandable column header.

This is intended to support the use case described in ant-design/ant-design#8791.

The implementation is ready for maintainer review. The corresponding Ant Design integration will follow once the API is accepted and released.

API

  • Add expandable.showExpandAll to enable the header control.
  • Add expandable.onExpandAll to observe expand/collapse-all actions.
  • Add a unified components.ExpandIcon for both row expansion and the expand-all control.
  • Deprecate expandable.expandIcon, retaining it as a row-only fallback for backward compatibility.
  • Allow expandable.columnTitle to be a render function receiving the generated expand-all control.

components.ExpandIcon receives:

  • type: 'row' | 'all'
  • expanded
  • expandable
  • onClick
  • prefixCls
  • record for row controls only

Behavior

  • The feature is disabled by default.
  • Only rows allowed by rowExpandable are affected.
  • Controlled and uncontrolled expandedRowKeys are supported.
  • Existing unrelated expanded keys are preserved.
  • components.ExpandIcon takes precedence over the deprecated expandable.expandIcon fallback.
  • The unified component supports both expandedRowRender and nested/tree row controls.
  • The expand-all header control is currently limited to expandedRowRender tables.
  • The default expand-all control is keyboard accessible.

Summary by CodeRabbit

  • 新功能
    • 新增“全部展开/收起”控件,支持一键操作所有可展开行。
    • 支持自定义行展开图标、展开全部图标和展开列标题。
    • 新增展开全部状态回调,并支持按条件筛选可展开行。
    • expandIcon 标记为弃用,建议使用 components.ExpandIcon
  • 文档
    • 更新中英文文档,补充相关配置项、回调及迁移说明。
  • 测试
    • 增加全部展开、收起、自定义图标及条件筛选等场景测试。

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@nikzanda is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

新增展开全部行功能。该功能支持默认或自定义图标、批量展开与收起、可展开行过滤、受控状态同步和自定义展开列表头。README 文档同步更新。

Changes

展开全部行支持

Layer / File(s) Summary
公开配置与图标渲染
src/interface.ts, src/utils/expandUtil.tsx, src/index.ts, assets/index.less
新增 ExpandIcon 类型、展开全部配置和默认图标渲染。旧版 expandable.expandIcon 保留为行图标回退。
展开状态与展开列
src/hooks/useExpand.ts, src/hooks/useColumns/index.tsx, src/Table.tsx, src/context/TableContext.tsx, src/hooks/useRowInfo.tsx, src/Body/BodyRow.tsx
useExpand 管理可展开行、整体状态和批量处理器。Table 与上下文向展开列和行传递 ExpandIconexpandAllInfo
集成、验证与文档
tests/ExpandRow.spec.jsx, README.md, README.zh-CN.md
测试覆盖自定义图标、可访问性、不可展开状态、批量操作、受控状态和标题渲染。中英文文档同步更新。

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Table
  participant useExpand
  participant useColumns
  participant ExpandIcon
  Table->>useExpand: 获取展开全部状态和处理器
  useExpand-->>Table: 返回 expandAllInfo
  Table->>useColumns: 传递 ExpandIcon 和 expandAllInfo
  useColumns->>ExpandIcon: 渲染 type="all" 图标
  ExpandIcon->>useExpand: 触发展开或收起全部行
  useExpand-->>Table: 更新 expandedRowKeys
Loading

Suggested reviewers: afc163

Poem

Poem

兔子轻点展开钮,
行列一齐向前跑。
再点一次全收起,
可展开行听指令。
测试守住每一步。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了在可展开列标题中新增全部展开和收起控件这一主要变更。
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 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.

@nikzanda
nikzanda force-pushed the feat/expand-all-header branch from 22bede1 to ef33496 Compare July 31, 2026 10:18
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.08%. Comparing base (60ab7b7) to head (fd16077).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1505      +/-   ##
==========================================
+ Coverage   99.05%   99.08%   +0.03%     
==========================================
  Files          45       45              
  Lines        1376     1426      +50     
  Branches      413      432      +19     
==========================================
+ Hits         1363     1413      +50     
  Misses         13       13              

☔ View full report in Codecov by Harness.
📢 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.

@nikzanda
nikzanda marked this pull request as ready for review July 31, 2026 10:20
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/utils/expandUtil.tsx`:
- Around line 57-64: Update the expand-all control in the rendered component
from a span to a native button with type="button", preserving its className and
onClick behavior. Add an aria-label that reflects the current expanded state and
bind aria-expanded to expanded. Extend the interaction tests to verify Tab focus
and activation via Enter and Space.
🪄 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 Plus

Run ID: 3313343f-3c8c-4313-babe-050aa6c7b4e7

📥 Commits

Reviewing files that changed from the base of the PR and between 08188d3 and ef33496.

📒 Files selected for processing (8)
  • README.md
  • README.zh-CN.md
  • src/Table.tsx
  • src/hooks/useColumns/index.tsx
  • src/hooks/useExpand.ts
  • src/interface.ts
  • src/utils/expandUtil.tsx
  • tests/ExpandRow.spec.jsx

Comment thread src/utils/expandUtil.tsx
@nikzanda

Copy link
Copy Markdown
Contributor Author

@afc163 @zombieJ, the implementation is now complete and this PR is ready for review.

It includes the expand-all API, controlled and uncontrolled behavior, rowExpandable filtering, keyboard accessibility, documentation, and regression tests. All modified and coverable lines are covered by tests, and CodeRabbit reports no remaining actionable comments.

When you have time, could you please review the proposed API and implementation? I’m happy to make any adjustments needed before proceeding with the Ant Design integration for ant-design/ant-design#8791. Thanks!

Comment thread src/hooks/useColumns/index.tsx Outdated
getRowKey: GetRowKey<RecordType>;
onTriggerExpand: TriggerEventHandler<RecordType>;
expandIcon?: RenderExpandIcon<RecordType>;
expandAllIcon?: RenderExpandAllIcon;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we can support components.ExpandIcon which support onClick expanded props for customize instead of passing by props

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@zombieJ I understand components.ExpandIcon as a replacement for expandable.expandAllIcon, used only for the expand-all control in the column header and receiving expanded and onClick.
The existing expandable.expandIcon behavior for individual rows would remain unchanged.

Please let me know if this matches what you had in mind, and I’ll update the implementation, typings, documentation, and tests accordingly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer introducing a unified components.ExpandIcon to replace both expandable.expandIcon and the new expandable.expandAllIcon, rather than keeping separate icon APIs for row expansion and expand-all.

My reasoning is:

  1. In most cases, the row expand control and the header expand-all control use the same component. If they need to look different, the component can distinguish between the row and header cases through the presence of record, or through a documented special marker in the props.
  2. components.ExpandIcon could later be integrated with the Ant Design ConfigProvider, enabling global customization. If the icon remains an expandable property, it can only be configured per Table and cannot be overridden globally through ConfigProvider.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification. I’ve updated the implementation to use a unified components.ExpandIcon for both row expansion and the expand-all control.

The component now receives:

  • type: 'row' | 'all'
  • expanded
  • expandable
  • onClick
  • prefixCls
  • record for row controls only

I also:

  • removed the new expandable.expandAllIcon API;
  • kept the existing expandable.expandIcon as a deprecated row-only fallback for backward compatibility;
  • made components.ExpandIcon take precedence over the deprecated fallback;
  • applied the unified component to both expandedRowRender and nested/tree rows;
  • updated the English and Chinese documentation;
  • added regression coverage for both icon types, precedence, the deprecated fallback, and nested rows.

@nikzanda
nikzanda requested a review from zombieJ August 5, 2026 10:58
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