From 7b4123258b598933a24190b0cc9e0e1dff0f55a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Wed, 11 Dec 2019 14:14:52 +0800 Subject: [PATCH] fix: table should not show sorter when sorter is falsy (#20187) fix #20096 --- .../table/__tests__/Table.sorter.test.js | 30 +++++++++++++++++++ components/table/hooks/useSorter.tsx | 4 +-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/components/table/__tests__/Table.sorter.test.js b/components/table/__tests__/Table.sorter.test.js index 3537eca590..98c290d088 100644 --- a/components/table/__tests__/Table.sorter.test.js +++ b/components/table/__tests__/Table.sorter.test.js @@ -639,4 +639,34 @@ describe('Table.sorter', () => { ); expect(wrapper.render()).toMatchSnapshot(); }); + + // https://github.com/ant-design/ant-design/issues/20096 + it('invalidate sorter should not display sorter button', () => { + const wrapper = mount( + , + ); + + expect(wrapper.find('.ant-table-column-sorter-inner')).toHaveLength(0); + }); }); diff --git a/components/table/hooks/useSorter.tsx b/components/table/hooks/useSorter.tsx index 086fba0102..4db160c331 100644 --- a/components/table/hooks/useSorter.tsx +++ b/components/table/hooks/useSorter.tsx @@ -59,7 +59,7 @@ function collectSortStates( if ('children' in column) { sortStates = [...sortStates, ...collectSortStates(column.children, init, columnPos)]; - } else if ('sorter' in column) { + } else if (column.sorter) { if ('sortOrder' in column) { // Controlled sortStates.push({ @@ -95,7 +95,7 @@ function injectSorter( const columnPos = getColumnPos(index, pos); let newColumn: ColumnsType[number] = column; - if ('sorter' in newColumn) { + if (newColumn.sorter) { const sortDirections: SortOrder[] = newColumn.sortDirections || defaultSortDirections; const columnKey = getColumnKey(newColumn, columnPos); const sorterState = sorterSates.find(({ key }) => key === columnKey);