fix: table should not show sorter when sorter is falsy (#20187)

fix #20096
This commit is contained in:
二货机器人 2019-12-11 14:14:52 +08:00 committed by GitHub
parent d0d521fc63
commit 7b4123258b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View File

@ -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(
<Table
columns={[
{
title: 'Name',
dataIndex: 'name',
key: 'name',
sorter: false,
},
{
title: 'Age',
dataIndex: 'age',
key: 'age',
sorter: null,
},
{
title: 'Address',
dataIndex: 'address',
key: 'address',
sorter: undefined,
},
]}
/>,
);
expect(wrapper.find('.ant-table-column-sorter-inner')).toHaveLength(0);
});
});

View File

@ -59,7 +59,7 @@ function collectSortStates<RecordType>(
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<RecordType>(
const columnPos = getColumnPos(index, pos);
let newColumn: ColumnsType<RecordType>[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);