mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
fix(#19132): fix component tree defaultExpandAll does not work when using treeData
This commit is contained in:
parent
311a6c0917
commit
5fff041e8a
@ -13,7 +13,12 @@ import Tree, {
|
||||
AntTreeNodeSelectedEvent,
|
||||
AntTreeNode,
|
||||
} from './Tree';
|
||||
import { calcRangeKeys, getFullKeyList, convertDirectoryKeysToNodes } from './util';
|
||||
import {
|
||||
calcRangeKeys,
|
||||
getFullKeyList,
|
||||
convertDirectoryKeysToNodes,
|
||||
getFullKeyListByTreeData,
|
||||
} from './util';
|
||||
import Icon from '../icon';
|
||||
|
||||
export type ExpandAction = false | 'click' | 'doubleClick';
|
||||
@ -82,7 +87,15 @@ class DirectoryTree extends React.Component<DirectoryTreeProps, DirectoryTreeSta
|
||||
|
||||
// Expanded keys
|
||||
if (defaultExpandAll) {
|
||||
this.state.expandedKeys = getFullKeyList(props.children);
|
||||
const expandedKeysByChildren = getFullKeyList(props.children);
|
||||
this.state.expandedKeys = expandedKeysByChildren;
|
||||
if (
|
||||
!!props.treeData &&
|
||||
Array.isArray(expandedKeysByChildren) &&
|
||||
expandedKeysByChildren.length === 0
|
||||
) {
|
||||
this.state.expandedKeys = getFullKeyListByTreeData(props.treeData);
|
||||
}
|
||||
} else if (defaultExpandParent) {
|
||||
this.state.expandedKeys = conductExpandParent(
|
||||
expandedKeys || defaultExpandedKeys,
|
||||
|
@ -101,3 +101,12 @@ export function convertDirectoryKeysToNodes(
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
export function getFullKeyListByTreeData(treeData: any[]): any {
|
||||
for (const item of treeData) {
|
||||
if (item.children) {
|
||||
return getFullKeyListByTreeData(item.children).concat([item.key]);
|
||||
}
|
||||
return [item.key];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user