Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Table expand icon not clickable when expandRowByClick is set #20808

Merged
merged 1 commit into from Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/table/ExpandIcon.tsx
Expand Up @@ -23,7 +23,10 @@ function renderExpandIcon(locale: TableLocale) {
return (
<button
type="button"
onClick={e => onExpand(record, e!)}
onClick={e => {
onExpand(record, e!);
e.stopPropagation();
}}
className={classNames(iconPrefix, {
[`${iconPrefix}-spaced`]: !expandable,
[`${iconPrefix}-expanded`]: expandable && expanded,
Expand Down
59 changes: 51 additions & 8 deletions components/table/__tests__/Table.expand.test.js
Expand Up @@ -11,19 +11,27 @@ const columns = [
},
];

const John = {
key: '1',
firstName: 'John',
lastName: 'Brown',
age: 32,
};

const Jim = {
key: '2',
firstName: 'Jim',
lastName: 'Green',
age: 42,
};

const data = [
{
key: '1',
firstName: 'John',
lastName: 'Brown',
age: 32,
...John,

children: [
{
key: '2',
firstName: 'Jim',
lastName: 'Green',
age: 42,
...Jim,
},
],
},
Expand All @@ -43,4 +51,39 @@ describe('Table.expand', () => {
const wrapper = mount(<Table columns={[]} dataSource={data} expandIconColumnIndex={1} />);
expect(wrapper.render()).toMatchSnapshot();
});

it('expandRowByClick should not block click icon', () => {
const wrapper = mount(
<Table
columns={columns}
dataSource={[John, Jim]}
expandable={{
expandRowByClick: true,
expandedRowRender: () => '',
}}
/>,
);

wrapper
.find('.ant-table-row-expand-icon')
.first()
.simulate('click');
expect(
wrapper
.find('.ant-table-row-expand-icon')
.first()
.hasClass('ant-table-row-expand-icon-expanded'),
).toBeTruthy();

wrapper
.find('.ant-table-row-expand-icon')
.first()
.simulate('click');
expect(
wrapper
.find('.ant-table-row-expand-icon')
.first()
.hasClass('ant-table-row-expand-icon-collapsed'),
).toBeTruthy();
});
});