fix: Transfer checkbox disabled error (#40048)

* fix: Transfer checkbox disabled error

* add test case
This commit is contained in:
lijianan 2023-01-08 15:35:28 +08:00 committed by GitHub
parent c0ce8e5455
commit 4b4e7cb6f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -20,6 +20,11 @@ const listProps: TransferListProps<KeyWiseTransferItem> = {
dataSource: undefined as unknown as KeyWiseTransferItem[],
};
const emptyListProps: TransferListProps<KeyWiseTransferItem> = {
...listCommonProps,
dataSource: [],
};
describe('Transfer.List', () => {
it('should render correctly', () => {
const { container } = render(<List {...listCommonProps} />);
@ -39,4 +44,24 @@ describe('Transfer.List', () => {
render(<List {...listProps} />);
}).not.toThrow();
});
it('Checkbox should disabled when dataSource is empty', () => {
const { container } = render(<List {...emptyListProps} />);
expect(container.querySelector<HTMLLabelElement>('label.ant-checkbox-wrapper')).toHaveClass(
'ant-checkbox-wrapper-disabled',
);
expect(container.querySelector<HTMLSpanElement>('span.ant-checkbox')).toHaveClass(
'ant-checkbox-disabled',
);
});
it('Checkbox should not disabled when dataSource not is empty', () => {
const { container } = render(<List {...listCommonProps} />);
expect(container.querySelector<HTMLLabelElement>('label.ant-checkbox-wrapper')).not.toHaveClass(
'ant-checkbox-wrapper-disabled',
);
expect(container.querySelector<HTMLSpanElement>('span.ant-checkbox')).not.toHaveClass(
'ant-checkbox-disabled',
);
});
});

View File

@ -238,7 +238,7 @@ const TransferList = <RecordType extends KeyWiseTransferItem>(
const checkBox = (
<Checkbox
disabled={filteredItems.length === 0 || props.disabled}
disabled={dataSource.length === 0 || props.disabled}
checked={checkStatus === 'all'}
indeterminate={checkStatus === 'part'}
className={`${prefixCls}-checkbox`}