bug fix : expand all leaf nodes in root level (#47567)

* fix table's scrollbar background color in dark mode

* docs : fix "fille" with "filled"

* expand all leaf nodes in root level

* Add type annotation

* code style format

* [CodeFactor] Apply fixes to commit 116efaf

[ci skip] [skip ci]

* simplify the code and add the corresponding testing module

---------

Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
SuperYY 2024-02-24 12:42:21 +08:00 committed by GitHub
parent 7d782ad642
commit 1b696510e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -65,7 +65,7 @@ const DirectoryTree: React.ForwardRefRenderFunction<RcTree, DirectoryTreeProps>
keyEntities,
);
} else {
initExpandedKeys = (props.expandedKeys || defaultExpandedKeys)!;
initExpandedKeys = props.expandedKeys || defaultExpandedKeys || [];
}
return initExpandedKeys;
};

View File

@ -123,6 +123,30 @@ describe('Directory Tree', () => {
expect(asFragment().firstChild).toMatchSnapshot();
});
it('select multi nodes when shift key down', () => {
const treeData = [
{ title: 'leaf 0-0', key: '0-0-0', isLeaf: true },
{ title: 'leaf 0-1', key: '0-0-1', isLeaf: true },
{ title: 'leaf 1-0', key: '0-1-0', isLeaf: true },
{ title: 'leaf 1-1', key: '0-1-1', isLeaf: true },
];
const { container } = render(
<DirectoryTree multiple defaultExpandAll={false} treeData={treeData} />,
);
expect(container.querySelectorAll('.ant-tree-node-content-wrapper').length).toBe(4);
expect(container.querySelectorAll('.ant-tree-node-selected').length).toBe(0);
const leaf0 = container.querySelectorAll('.ant-tree-node-content-wrapper')[0];
const leaf1 = container.querySelectorAll('.ant-tree-node-content-wrapper')[1];
const leaf2 = container.querySelectorAll('.ant-tree-node-content-wrapper')[2];
const leaf3 = container.querySelectorAll('.ant-tree-node-content-wrapper')[3];
fireEvent.click(leaf2);
fireEvent.click(leaf0, { shiftKey: true });
expect(leaf0).toHaveClass('ant-tree-node-selected');
expect(leaf1).toHaveClass('ant-tree-node-selected');
expect(leaf2).toHaveClass('ant-tree-node-selected');
expect(leaf3).not.toHaveClass('ant-tree-node-selected');
});
it('DirectoryTree should expend all when use treeData and defaultExpandAll is true', () => {
const treeData = [
{