Skip to content

fix: apply expandedRowClassName to virtual tree rows#1482

Merged
afc163 merged 1 commit intoreact-component:masterfrom
QDyanbing:fix-57758-expanded-row-classname
Apr 24, 2026
Merged

fix: apply expandedRowClassName to virtual tree rows#1482
afc163 merged 1 commit intoreact-component:masterfrom
QDyanbing:fix-57758-expanded-row-classname

Conversation

@QDyanbing
Copy link
Copy Markdown
Contributor

@QDyanbing QDyanbing commented Apr 23, 2026

变更说明

  • 修复 virtual 模式下树形展开子行未应用 expandedRowClassName 的问题
  • 保持 expandedRowRender 展开行现有行为不变
  • 补充虚拟表格树形展开场景的回归测试

验证

  • npx vitest run tests/Virtual.spec.tsx
  • npx vitest run tests/ExpandRow.spec.jsx -t "renders expend row class correctly using children without expandedRowRender"

Fix ant-design/ant-design#57758

Summary by CodeRabbit

发行说明

  • Bug 修复
    • 虚拟表现在可正确地将展开行样式应用到树形展开产生的行中。

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

@QDyanbing 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
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 updates the BodyLine component in the virtual table to correctly apply expandedRowClassName to tree rows. The logic for computing the expanded class name was moved outside the conditional block and is now applied to the row's class list when the row indent is at least one. Additionally, a new test case was added to Virtual.spec.tsx to verify that child rows in a tree structure receive the specified class name. I have no feedback to provide as there were no review comments to evaluate.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

快速概览

该变更修复了虚拟表格中expandable.expandedRowClassName未被应用于展开行的问题。通过调整BodyLine组件中展开样式类名的计算时机,确保该样式类在树形展开时正确应用,并新增了相应的单元测试进行验证。

变更详情

分组 / 文件 变更摘要
虚拟表格展开行样式修复
src/VirtualTable/BodyLine.tsx
expandedClsName的计算提前至条件分支外,使其在indent >= 1时无条件应用到主渲染行的className中,修复虚拟表格展开行样式失效的问题。
虚拟表格展开行样式测试
tests/Virtual.spec.tsx
新增单元测试验证虚拟表格中expandable.expandedRowClassName能正确应用于树形展开的子行元素。

预计代码审查工作量

🎯 2 (Simple) | ⏱️ ~10 分钟

相关的 PR

建议审阅者

  • afc163
  • zombieJ
  • MadCcc

兔子的贺诗

🐰 样式类名藏得深,展开行里没踪影,
虚拟表格现新欢,树枝摇曳披彩衣!
一行代码挪位置,测试验证心欢喜。✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: applying expandedRowClassName to virtual tree rows, which is the core change in the PR.
Linked Issues check ✅ Passed The PR directly addresses the linked issue #57758 by modifying BodyLine.tsx to apply expandedRowClassName to expanded rows in virtual mode, with test coverage added.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the expandedRowClassName application in virtual mode; no unrelated or out-of-scope modifications detected.
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

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

🧹 Nitpick comments (1)
tests/Virtual.spec.tsx (1)

186-210: 建议:补充函数式 expandedRowClassName 的覆盖。

紧邻的 basic 用例对 expandedRowClassName 同时验证了字符串与函数两种形态(Line 170 的 ['bamboo', () => 'bamboo'])。本用例是本次修复的核心回归测试,但仅覆盖字符串形态,建议参照 basic 模式也覆盖函数形态,以确保 computedExpandedClassNameindent >= 1 的树行下能正确接收 (record, index, indent) 并返回类名。

♻️ 参考改写
-    it('applies expanded row class to tree rows', () => {
-      const { container } = getTable({
-        data: [
-          {
-            name: 'parent',
-            age: 0,
-            address: 'address0',
-            children: [
-              {
-                name: 'child',
-                age: 1,
-                address: 'address1',
-              },
-            ],
-          },
-        ],
-        expandable: {
-          expandedRowKeys: ['parent'],
-          expandedRowClassName: 'bamboo',
-          expandIcon: () => <span className="custom-expand-icon" />,
-        },
-      });
-
-      expect(container.querySelector('[data-row-key="child"]')).toHaveClass('bamboo');
-    });
+    it('applies expanded row class to tree rows', () => {
+      (['bamboo', () => 'bamboo'] as const).forEach(cls => {
+        const { container } = getTable({
+          data: [
+            {
+              name: 'parent',
+              age: 0,
+              address: 'address0',
+              children: [
+                {
+                  name: 'child',
+                  age: 1,
+                  address: 'address1',
+                },
+              ],
+            },
+          ],
+          expandable: {
+            expandedRowKeys: ['parent'],
+            expandedRowClassName: cls,
+            expandIcon: () => <span className="custom-expand-icon" />,
+          },
+        });
+
+        expect(container.querySelector('[data-row-key="child"]')).toHaveClass('bamboo');
+        // 父行(indent=0)不应被附加该类名
+        expect(container.querySelector('[data-row-key="parent"]')).not.toHaveClass('bamboo');
+      });
+    });

附带断言父行(indent=0)不带该类名,可以防止未来不小心把 indent >= 1 守卫移除而引入回归。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Virtual.spec.tsx` around lines 186 - 210, Update the failing test to
also exercise the functional form of expandedRowClassName and assert the parent
(indent=0) does not receive the class: when calling getTable pass
expandable.expandedRowClassName as a function (e.g., (record, index, indent) =>
'bamboo') in addition to the string case so computedExpandedClassName is
executed for indent >= 1; assert
container.querySelector('[data-row-key="child"]') has the 'bamboo' class and
container.querySelector('[data-row-key="parent"]') does not, ensuring the indent
guard remains effective.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/Virtual.spec.tsx`:
- Around line 186-210: Update the failing test to also exercise the functional
form of expandedRowClassName and assert the parent (indent=0) does not receive
the class: when calling getTable pass expandable.expandedRowClassName as a
function (e.g., (record, index, indent) => 'bamboo') in addition to the string
case so computedExpandedClassName is executed for indent >= 1; assert
container.querySelector('[data-row-key="child"]') has the 'bamboo' class and
container.querySelector('[data-row-key="parent"]') does not, ensuring the indent
guard remains effective.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1c172bad-e312-4826-9486-978d749d23e8

📥 Commits

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

📒 Files selected for processing (2)
  • src/VirtualTable/BodyLine.tsx
  • tests/Virtual.spec.tsx

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.11%. Comparing base (29dcc3e) to head (8e26cb4).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1482   +/-   ##
=======================================
  Coverage   96.11%   96.11%           
=======================================
  Files          57       57           
  Lines        3447     3448    +1     
  Branches      635      635           
=======================================
+ Hits         3313     3314    +1     
  Misses        129      129           
  Partials        5        5           

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

@afc163 afc163 merged commit 80fcd5e into react-component:master Apr 24, 2026
7 of 8 checks passed
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.

expandedRowClassName is not applied to expanded rows when using virtual in Table component

2 participants