Browse Source

fix: Table selectAll should not checked when all the checkbox is disabled (#20968)

pull/20972/head
二货机器人 5 years ago
committed by GitHub
parent
commit
ddfce71532
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      components/table/__tests__/Table.rowSelection.test.js
  2. 17
      components/table/hooks/useSelection.tsx

15
components/table/__tests__/Table.rowSelection.test.js

@ -764,4 +764,19 @@ describe('Table.rowSelection', () => {
.simulate('click');
}).not.toThrow();
});
it('all disabled should not make select all checked', () => {
const wrapper = mount(
createTable({
rowSelection: {
getCheckboxProps: () => ({
disabled: true,
}),
},
}),
);
expect(wrapper.find('thead .ant-checkbox-input').props().disabled).toBeTruthy();
expect(wrapper.find('thead .ant-checkbox-input').props().checked).toBeFalsy();
});
});

17
components/table/hooks/useSelection.tsx

@ -285,20 +285,19 @@ export default function useSelection<RecordType>(
);
}
const allDisabled = flattedData.every((record, index) => {
const key = getRowKey(record, index);
const checkboxProps = checkboxPropsMap.get(key) || {};
return checkboxProps.disabled;
});
title = (
<div className={`${prefixCls}-selection`}>
<Checkbox
checked={!!flattedData.length && checkedCurrentAll}
checked={!allDisabled && !!flattedData.length && checkedCurrentAll}
indeterminate={!checkedCurrentAll && checkedCurrentSome}
onChange={onSelectAllChange}
disabled={
flattedData.length === 0 ||
flattedData.every((record, index) => {
const key = getRowKey(record, index);
const checkboxProps = checkboxPropsMap.get(key) || {};
return checkboxProps.disabled;
})
}
disabled={flattedData.length === 0 || allDisabled}
/>
{customizeSelections}
</div>

Loading…
Cancel
Save