diff --git a/src/components/tree/index.tsx b/src/components/tree/index.tsx index a64ea95a8..c1e4c1b34 100644 --- a/src/components/tree/index.tsx +++ b/src/components/tree/index.tsx @@ -1,4 +1,10 @@ -import React, { useState, useRef, useCallback, useLayoutEffect } from 'react'; +import React, { + useState, + useRef, + useCallback, + useLayoutEffect, + useEffect, +} from 'react'; import { Icon } from 'mo/components/icon'; import { debounce } from 'lodash'; import { classNames } from 'mo/common/className'; @@ -56,6 +62,7 @@ export interface ITreeProps { className?: string; draggable?: boolean; expandKeys?: UniqueId[]; + activeKey?: UniqueId; onExpand?: (expandedKeys: React.Key[], node: ITreeNodeItemProps) => void; onSelect?: (node: ITreeNodeItemProps, isUpdate?) => void; onTreeClick?: () => void; @@ -77,6 +84,7 @@ const TreeView = ({ data = [], draggable = false, expandKeys: controlExpandKeys, + activeKey: controlActiveKey, onExpand, onDropTree, onRightClick, @@ -434,6 +442,10 @@ const TreeView = ({ } }, [data]); + useEffect(() => { + controlActiveKey && setActiveKey(controlActiveKey.toString()); + }, [controlActiveKey]); + return (
= (props) => { ...restProps } = props; - const { data = [], folderPanelContextMenu = [], expandKeys } = folderTree; + const { + data = [], + folderPanelContextMenu = [], + expandKeys, + current, + } = folderTree; const handleAddRootFolder = () => { createTreeNode?.('RootFolder'); @@ -228,6 +233,7 @@ const FolderTree: React.FunctionComponent = (props) => {