Browse Source
fix: Table selectAll should not checked when all the checkbox is disabled (#20968)
pull/20972/head
二货机器人
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
23 additions and
9 deletions
-
components/table/__tests__/Table.rowSelection.test.js
-
components/table/hooks/useSelection.tsx
|
|
@ -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(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
@ -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> |
|
|
|