From 585f239c35fb9ae38d3f7c594dc1aa0663a0ae3d Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 6 May 2020 18:09:51 +0800 Subject: [PATCH] fix table icon cannot expand when has expandRowByClick --- examples/expandIcon.tsx | 1 - src/Table.tsx | 3 ++- tests/ExpandRow.spec.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/examples/expandIcon.tsx b/examples/expandIcon.tsx index 998fd26f2..9dd8ea3ef 100644 --- a/examples/expandIcon.tsx +++ b/examples/expandIcon.tsx @@ -42,7 +42,6 @@ const Demo = () => ( columns={columns} data={data} expandable={{ - expandRowByClick: true, expandedRowRender: record =>

extra: {record.a}

, onExpand, expandIcon: CustomExpandIcon, diff --git a/src/Table.tsx b/src/Table.tsx index a89400d3b..d3f7608f0 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -342,7 +342,8 @@ function Table(props: TableProps {} : onTriggerExpand, + // https://github.com/ant-design/ant-design/issues/23894 + onTriggerExpand: expandRowByClick && expandIcon ? () => {} : onTriggerExpand, expandIcon: mergedExpandIcon, expandIconColumnIndex, direction, diff --git a/tests/ExpandRow.spec.js b/tests/ExpandRow.spec.js index ad12f7a64..0627fd357 100644 --- a/tests/ExpandRow.spec.js +++ b/tests/ExpandRow.spec.js @@ -399,4 +399,32 @@ describe('Table.Expand', () => { expect(onExpand).toHaveBeenCalledWith(false, data[0]); expect(onExpand).toHaveBeenCalledTimes(2); }); + + // https://github.com/ant-design/ant-design/issues/23894 + it('should be collapsible when `expandRowByClick` without custom `expandIcon`', () => { + const data = [{ key: 0, name: 'Lucy', age: 27, children: [{ key: 1, name: 'Jack', age: 28 }] }]; + const onExpand = jest.fn(); + const wrapper = mount( + createTable({ + expandable: { + expandedRowRender, + expandRowByClick: true, + onExpand, + }, + data, + }), + ); + wrapper + .find('.rc-table-row-expand-icon') + .first() + .simulate('click'); + expect(onExpand).toHaveBeenCalledWith(true, data[0]); + expect(onExpand).toHaveBeenCalledTimes(1); + wrapper + .find('.rc-table-row-expand-icon') + .first() + .simulate('click'); + expect(onExpand).toHaveBeenCalledWith(false, data[0]); + expect(onExpand).toHaveBeenCalledTimes(2); + }); });