Merge branch 'master' into fix/duplicate-style-tags
Some checks are pending
Publish Any Commit / build (push) Waiting to run
✅ test / lint (push) Waiting to run
✅ test / test-react-legacy (16, 1/2) (push) Waiting to run
✅ test / test-react-legacy (16, 2/2) (push) Waiting to run
✅ test / test-react-legacy (17, 1/2) (push) Waiting to run
✅ test / test-react-legacy (17, 2/2) (push) Waiting to run
✅ test / test-node (push) Waiting to run
✅ test / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test / test-coverage (push) Blocked by required conditions
✅ test / build (push) Waiting to run
✅ test / test lib/es module (es, 1/2) (push) Waiting to run
✅ test / test lib/es module (es, 2/2) (push) Waiting to run
✅ test / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test / test lib/es module (lib, 2/2) (push) Waiting to run

This commit is contained in:
🏎️ Imer 2024-12-06 01:56:28 +08:00 committed by GitHub
commit 41cc696c89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 7 deletions

View File

@ -34,7 +34,7 @@ const ListItem = <RecordType extends KeyWiseTransferItem>(props: ListItemProps<R
const className = classNames(`${prefixCls}-content-item`, {
[`${prefixCls}-content-item-disabled`]: disabled || item.disabled,
[`${prefixCls}-content-item-checked`]: checked,
[`${prefixCls}-content-item-checked`]: checked && !item.disabled,
});
let title: string | undefined;

View File

@ -663,6 +663,17 @@ describe('Transfer', () => {
expect(getByText('1 of 2')).toBeTruthy();
});
it('should disable transfer operation button when some items are set to selected but also disabled', () => {
const dataSource = listDisabledProps.dataSource.map((d) => ({
...d,
disabled: true,
}));
const { container } = render(<Transfer {...listDisabledProps} dataSource={dataSource} />);
expect(
container.querySelectorAll<HTMLDivElement>('.ant-transfer-operation button').item(0),
).toBeDisabled();
});
describe('pagination', () => {
it('boolean', async () => {
const { getByTitle } = render(<Transfer {...listDisabledProps} pagination />);

View File

@ -66,6 +66,23 @@ describe('Transfer.List', () => {
);
});
it('should disabled all select checkbox when each item of dataSource is disabled', () => {
const allDisabledListProps: TransferListProps<KeyWiseTransferItem> = {
...listCommonProps,
dataSource: listCommonProps.dataSource.map((d) => ({
...d,
disabled: true,
})),
};
const { container } = render(<List {...allDisabledListProps} />);
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('support custom dropdown Icon', () => {
const { container } = render(
<List

View File

@ -404,8 +404,12 @@ const Transfer = <RecordType extends TransferItem = TransferItem>(
const mergedStatus = getMergedStatus(status, customStatus);
const mergedPagination = !children && pagination;
const leftActive = targetSelectedKeys.length > 0;
const rightActive = sourceSelectedKeys.length > 0;
const leftActive =
rightDataSource.filter((d) => targetSelectedKeys.includes(d.key as TransferKey) && !d.disabled)
.length > 0;
const rightActive =
leftDataSource.filter((d) => sourceSelectedKeys.includes(d.key as TransferKey) && !d.disabled)
.length > 0;
const cls = classNames(
prefixCls,

View File

@ -187,8 +187,12 @@ const TransferList = <RecordType extends KeyWiseTransferItem>(
return [filterItems, filterRenderItems] as const;
}, [dataSource, filterValue]);
const checkedActiveItems = useMemo<RecordType[]>(() => {
return filteredItems.filter((item) => checkedKeys.includes(item.key) && !item.disabled);
}, [checkedKeys, filteredItems]);
const checkStatus = useMemo<string>(() => {
if (checkedKeys.length === 0) {
if (checkedActiveItems.length === 0) {
return 'none';
}
const checkedKeysMap = groupKeysMap(checkedKeys);
@ -196,7 +200,7 @@ const TransferList = <RecordType extends KeyWiseTransferItem>(
return 'all';
}
return 'part';
}, [checkedKeys, filteredItems]);
}, [checkedKeys, checkedActiveItems]);
const listBody = useMemo<React.ReactNode>(() => {
const search = showSearch ? (
@ -254,7 +258,7 @@ const TransferList = <RecordType extends KeyWiseTransferItem>(
const checkBox = (
<Checkbox
disabled={dataSource.length === 0 || disabled}
disabled={dataSource.filter((d) => !d.disabled).length === 0 || disabled}
checked={checkStatus === 'all'}
indeterminate={checkStatus === 'part'}
className={`${prefixCls}-checkbox`}
@ -380,7 +384,7 @@ const TransferList = <RecordType extends KeyWiseTransferItem>(
</>
) : null}
<span className={`${prefixCls}-header-selected`}>
{getSelectAllLabel(checkedKeys.length, filteredItems.length)}
{getSelectAllLabel(checkedActiveItems.length, filteredItems.length)}
</span>
<span className={`${prefixCls}-header-title`}>{titleText}</span>
</div>