Skip to content

Commit

Permalink
bug fix : expand all leaf nodes in root level (#47567)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
wkmyws and code-factor committed Feb 24, 2024
1 parent 7d782ad commit 1b69651
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/tree/DirectoryTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const DirectoryTree: React.ForwardRefRenderFunction<RcTree, DirectoryTreeProps>
keyEntities,
);
} else {
initExpandedKeys = (props.expandedKeys || defaultExpandedKeys)!;
initExpandedKeys = props.expandedKeys || defaultExpandedKeys || [];
}
return initExpandedKeys;
};
Expand Down
24 changes: 24 additions & 0 deletions components/tree/__tests__/directory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down

0 comments on commit 1b69651

Please sign in to comment.