diff --git a/components/table/Table.tsx b/components/table/Table.tsx index fda222ffc9..a0a491b6f4 100755 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -810,26 +810,17 @@ export default class Table extends React.Component, TableState< [`${prefixCls}-column-sort`]: isSortColumn && sortOrder, }), title: [ -
+
this.toggleSortOrder(column)} + > {column.title} {sortButton}
, filterDropdown, ], - onHeaderCell: sortButton ? (columnProps: ColumnProps) => { - // for onHeaderCell compatibility - const headerCellProps = column.onHeaderCell ? column.onHeaderCell(columnProps) : {}; - return { - onClick: (e: MouseEvent) => { - this.toggleSortOrder(column); - if (headerCellProps && headerCellProps.onClick) { - headerCellProps.onClick(e); - } - }, - title: locale.sortTitle, - ...headerCellProps, - }; - } : column.onHeaderCell, }; }); } diff --git a/components/table/__tests__/Table.rowSelection.test.js b/components/table/__tests__/Table.rowSelection.test.js index d153199467..7724430fde 100644 --- a/components/table/__tests__/Table.rowSelection.test.js +++ b/components/table/__tests__/Table.rowSelection.test.js @@ -423,7 +423,7 @@ describe('Table.rowSelection', () => { }); // https://github.com/ant-design/ant-design/issues/11042 - it('add columnTitle for rowSelection', () => { + it.only('add columnTitle for rowSelection', () => { const wrapper = mount( { }} /> ); - expect(wrapper.find('thead tr span').at(0).text()).toBe('多选'); + expect(wrapper.find('thead tr div').at(0).text()).toBe('多选'); wrapper.setProps({ rowSelection: { type: 'radio', columnTitle: '单选', }, }); - expect(wrapper.find('thead tr span').at(0).text()).toBe('单选'); + expect(wrapper.find('thead tr div').at(0).text()).toBe('单选'); }); }); diff --git a/components/table/__tests__/Table.sorter.test.js b/components/table/__tests__/Table.sorter.test.js index b0cfd93261..f624de110a 100644 --- a/components/table/__tests__/Table.sorter.test.js +++ b/components/table/__tests__/Table.sorter.test.js @@ -60,11 +60,13 @@ describe('Table.sorter', () => { it('sort records', () => { const wrapper = mount(createTable()); - wrapper.find('.ant-table-column-sorter-up').simulate('click'); - expect(renderedNames(wrapper)).toEqual(['Jack', 'Jerry', 'Lucy', 'Tom']); - - wrapper.find('.ant-table-column-sorter-down').simulate('click'); + // descent + wrapper.find('.ant-table-column-sorters').simulate('click'); expect(renderedNames(wrapper)).toEqual(['Tom', 'Lucy', 'Jack', 'Jerry']); + + // ascent + wrapper.find('.ant-table-column-sorters').simulate('click'); + expect(renderedNames(wrapper)).toEqual(['Jack', 'Jerry', 'Lucy', 'Tom']); }); it('can be controlled by sortOrder', () => { @@ -92,13 +94,27 @@ describe('Table.sorter', () => { const handleChange = jest.fn(); const wrapper = mount(createTable({ onChange: handleChange })); - wrapper.find('.ant-table-column-sorter-up').simulate('click'); - - const sorter = handleChange.mock.calls[0][2]; - expect(sorter.column.dataIndex).toBe('name'); - expect(sorter.order).toBe('ascend'); - expect(sorter.field).toBe('name'); - expect(sorter.columnKey).toBe('name'); + // ascent + wrapper.find('.ant-table-column-sorters').simulate('click'); + const sorter1 = handleChange.mock.calls[0][2]; + expect(sorter1.column.dataIndex).toBe('name'); + expect(sorter1.order).toBe('descend'); + expect(sorter1.field).toBe('name'); + expect(sorter1.columnKey).toBe('name'); + + wrapper.find('.ant-table-column-sorters').simulate('click'); + const sorter2 = handleChange.mock.calls[1][2]; + expect(sorter2.column.dataIndex).toBe('name'); + expect(sorter2.order).toBe('ascend'); + expect(sorter2.field).toBe('name'); + expect(sorter2.columnKey).toBe('name'); + + wrapper.find('.ant-table-column-sorters').simulate('click'); + const sorter3 = handleChange.mock.calls[2][2]; + expect(sorter3.column).toBe(undefined); + expect(sorter3.order).toBe(undefined); + expect(sorter3.field).toBe(undefined); + expect(sorter3.columnKey).toBe(undefined); }); it('works with grouping columns in controlled mode', () => {