diff --git a/components/table/__tests__/Table.sorter.test.js b/components/table/__tests__/Table.sorter.test.js index 7974a7a9ac..104681220e 100644 --- a/components/table/__tests__/Table.sorter.test.js +++ b/components/table/__tests__/Table.sorter.test.js @@ -272,7 +272,7 @@ describe('Table.sorter', () => { }); // https://github.com/ant-design/ant-design/pull/12264#discussion_r218053034 - it('should sort from begining state when toggle from different columns', () => { + it('should sort from beginning state when toggle from different columns', () => { const columns = [ { title: 'name', @@ -790,4 +790,55 @@ describe('Table.sorter', () => { .hasClass('active'), ).toBeTruthy(); }); + + it('onChange with correct sorter for multiple', () => { + const groupColumns = [ + { + title: 'Math Score', + dataIndex: 'math', + sorter: { multiple: 1 }, + }, + { + title: 'English Score', + dataIndex: 'english', + sorter: { multiple: 2 }, + }, + ]; + + const groupData = [ + { + key: '1', + name: 'John Brown', + chinese: 98, + math: 60, + english: 70, + }, + ]; + + const onChange = jest.fn(); + const wrapper = mount(); + + function clickToMatchExpect(index, sorter) { + wrapper.find('.ant-table-column-sorters').at(index).simulate('click'); + + expect(onChange).toHaveBeenCalledWith( + expect.anything(), + expect.anything(), + expect.objectContaining(sorter), + expect.anything(), + ); + + onChange.mockReset(); + } + + // First + clickToMatchExpect(0, { field: 'math', order: 'ascend' }); + clickToMatchExpect(0, { field: 'math', order: 'descend' }); + clickToMatchExpect(0, { field: 'math', order: undefined }); + + // Last + clickToMatchExpect(1, { field: 'english', order: 'ascend' }); + clickToMatchExpect(1, { field: 'english', order: 'descend' }); + clickToMatchExpect(1, { field: 'english', order: undefined }); + }); }); diff --git a/components/table/hooks/useSorter.tsx b/components/table/hooks/useSorter.tsx index 614a1e3788..52a4fc6299 100644 --- a/components/table/hooks/useSorter.tsx +++ b/components/table/hooks/useSorter.tsx @@ -231,7 +231,7 @@ function generateSorterInfo( // https://github.com/ant-design/ant-design/pull/19226 if (list.length === 0 && sorterStates.length) { return { - ...stateToInfo(sorterStates[0]), + ...stateToInfo(sorterStates[sorterStates.length - 1]), column: undefined, }; }