Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Transfer with rowKey will be unselectable #43115

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 26 additions & 4 deletions components/transfer/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,32 @@ describe('Transfer', () => {
expect(onScroll).toHaveBeenLastCalledWith('right', expect.anything());
});

it('should support rowKey is function', () => {
expect(() => {
render(<Transfer {...listCommonProps} rowKey={(record) => record.key} />);
}).not.toThrow();
it('support rowKey', () => {
const onSelectChange = jest.fn();

const Demo = () => {
const [selectedKeys, setSelectedKeys] = useState<string[]>([]);

return (
<Transfer
{...listCommonProps}
selectedKeys={selectedKeys}
rowKey={(record) => `key_${record.key}`}
onSelectChange={(keys) => {
onSelectChange(keys);
setSelectedKeys(keys);
}}
/>
);
};

const { container } = render(<Demo />);

fireEvent.click(container.querySelector('.ant-transfer-list-content input')!);
expect(onSelectChange).toHaveBeenCalledWith(['key_a']);
expect(
container.querySelector<HTMLInputElement>('.ant-transfer-list-content input')!.checked,
).toBeTruthy();
});

it('should support render value and label in item', () => {
Expand Down
6 changes: 5 additions & 1 deletion components/transfer/hooks/useSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ function filterKeys(keys: string[], dataKeys: Set<string>) {
return keys.length === filteredKeys.length ? keys : filteredKeys;
}

function flattenKeys(keys: Set<string>) {
return Array.from(keys).join(';');
}

export default function useSelection<T extends { key: string }>(
leftDataSource: T[],
rightDataSource: T[],
Expand Down Expand Up @@ -44,7 +48,7 @@ export default function useSelection<T extends { key: string }>(
React.useEffect(() => {
setSourceSelectedKeys(filterKeys(sourceSelectedKeys, leftKeys));
setTargetSelectedKeys(filterKeys(targetSelectedKeys, rightKeys));
}, [leftKeys, rightKeys]);
}, [flattenKeys(leftKeys), flattenKeys(rightKeys)]);

return [
// Keys
Expand Down
1 change: 1 addition & 0 deletions scripts/post-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const DEPRECIATED_VERSION = {
'https://github.com/ant-design/cssinjs/pull/108',
'https://github.com/ant-design/ant-design/pull/41993',
],
'5.6.2': ['https://github.com/ant-design/ant-design/issues/43113'],
};

function matchDeprecated(version) {
Expand Down