Skip to content

Commit 3d3712c

Browse files
committed
chore: Add columnType to confirm is expand column
1 parent e111fea commit 3d3712c

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

src/ColGroup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function ColGroup<RecordType>({ colWidths, columns, columCount }: ColGroupProps<
2121
const additionalProps = column && column[INTERNAL_COL_DEFINE];
2222

2323
if (width || additionalProps || mustInsert) {
24-
cols.unshift(<col key={i} style={{ width }} {...additionalProps} />);
24+
const { columnType, ...restAdditionalProps } = additionalProps || {};
25+
cols.unshift(<col key={i} style={{ width }} {...restAdditionalProps} />);
2526
mustInsert = true;
2627
}
2728
}

src/hooks/useColumns.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ function useColumns<RecordType>(
194194
const expandColumn = {
195195
[INTERNAL_COL_DEFINE]: {
196196
className: `${prefixCls}-expand-icon-col`,
197+
columnType: 'EXPAND_COLUMN',
197198
},
198199
title: '',
199200
fixed: fixedColumn,

tests/Table.spec.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
33
import { resetWarned } from 'rc-util/lib/warning';
4-
import Table from '../src';
4+
import Table, { INTERNAL_COL_DEFINE } from '../src';
55
import { INTERNAL_HOOKS } from '../src/Table';
66

77
describe('Table.Basic', () => {
@@ -750,15 +750,41 @@ describe('Table.Basic', () => {
750750
});
751751

752752
describe('internal api', () => {
753-
it('transformColumns', () => {
754-
const wrapper = mount(
755-
createTable({
756-
internalHooks: INTERNAL_HOOKS,
757-
transformColumns: columns => [{ title: 'before' }, ...columns, { title: 'after' }],
758-
}),
759-
);
753+
describe('transformColumns', () => {
754+
it('basic', () => {
755+
const wrapper = mount(
756+
createTable({
757+
internalHooks: INTERNAL_HOOKS,
758+
transformColumns: columns => [{ title: 'before' }, ...columns, { title: 'after' }],
759+
}),
760+
);
760761

761-
expect(wrapper.render()).toMatchSnapshot();
762+
expect(wrapper.render()).toMatchSnapshot();
763+
});
764+
765+
// Used for antd to check if is expand column
766+
// We'd better to move selection into rc-table also
767+
it('internal columnType', () => {
768+
let existExpandColumn = false;
769+
770+
mount(
771+
createTable({
772+
expandable: {
773+
expandedRowRender: () => null,
774+
},
775+
internalHooks: INTERNAL_HOOKS,
776+
transformColumns: columns => {
777+
console.log(columns);
778+
existExpandColumn = columns.some(
779+
col => col[INTERNAL_COL_DEFINE]?.columnType === 'EXPAND_COLUMN',
780+
);
781+
return columns;
782+
},
783+
}),
784+
);
785+
786+
expect(existExpandColumn).toBeTruthy();
787+
});
762788
});
763789

764790
it('internalRefs', () => {

tests/__snapshots__/Table.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ exports[`Table.Basic custom components scroll content with scroll 1`] = `
244244
</div>
245245
`;
246246

247-
exports[`Table.Basic internal api transformColumns 1`] = `
247+
exports[`Table.Basic internal api transformColumns basic 1`] = `
248248
<div
249249
class="rc-table"
250250
>

0 commit comments

Comments
 (0)