Skip to content

Commit 80fcd5e

Browse files
authored
fix: apply expandedRowClassName to virtual tree rows (#1482)
1 parent 29dcc3e commit 80fcd5e

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/VirtualTable/BodyLine.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) =>
3939
// ========================== Expand ==========================
4040
const { rowSupportExpand, expanded, rowProps, expandedRowRender, expandedRowClassName } = rowInfo;
4141

42+
const expandedClsName = computedExpandedClassName(expandedRowClassName, record, index, indent);
43+
4244
let expandRowNode: React.ReactElement<any>;
4345
if (rowSupportExpand && expanded) {
4446
const expandContent = expandedRowRender(record, index, indent + 1, expanded);
4547

46-
const expandedClsName = computedExpandedClassName(expandedRowClassName, record, index, indent);
47-
4848
let additionalProps: React.TdHTMLAttributes<HTMLElement> = {};
4949
if (fixColumn) {
5050
additionalProps = {
@@ -94,6 +94,7 @@ const BodyLine = React.forwardRef<HTMLDivElement, BodyLineProps>((props, ref) =>
9494
data-row-key={rowKey}
9595
ref={rowSupportExpand ? null : ref}
9696
className={clsx(className, `${prefixCls}-row`, rowProps?.className, {
97+
[expandedClsName]: indent >= 1,
9798
[`${prefixCls}-row-extra`]: extra,
9899
})}
99100
style={{ ...rowStyle, ...rowProps?.style }}

tests/Virtual.spec.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,32 @@ describe('Table.Virtual', () => {
183183
});
184184
});
185185

186+
it('applies expanded row class to tree rows', () => {
187+
const { container } = getTable({
188+
data: [
189+
{
190+
name: 'parent',
191+
age: 0,
192+
address: 'address0',
193+
children: [
194+
{
195+
name: 'child',
196+
age: 1,
197+
address: 'address1',
198+
},
199+
],
200+
},
201+
],
202+
expandable: {
203+
expandedRowKeys: ['parent'],
204+
expandedRowClassName: 'bamboo',
205+
expandIcon: () => <span className="custom-expand-icon" />,
206+
},
207+
});
208+
209+
expect(container.querySelector('[data-row-key="child"]')).toHaveClass('bamboo');
210+
});
211+
186212
it('fixed', () => {
187213
const { container } = getTable({
188214
columns: [

0 commit comments

Comments
 (0)