Skip to content

Commit 52d79b0

Browse files
authored
fix: use activeKey to control highlighting (#724) (#742)
1 parent 22f310f commit 52d79b0

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/components/tree/index.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import React, { useState, useRef, useCallback, useLayoutEffect } from 'react';
1+
import React, {
2+
useState,
3+
useRef,
4+
useCallback,
5+
useLayoutEffect,
6+
useEffect,
7+
} from 'react';
28
import { Icon } from 'mo/components/icon';
39
import { debounce } from 'lodash';
410
import { classNames } from 'mo/common/className';
@@ -56,6 +62,7 @@ export interface ITreeProps {
5662
className?: string;
5763
draggable?: boolean;
5864
expandKeys?: UniqueId[];
65+
activeKey?: UniqueId;
5966
onExpand?: (expandedKeys: React.Key[], node: ITreeNodeItemProps) => void;
6067
onSelect?: (node: ITreeNodeItemProps, isUpdate?) => void;
6168
onTreeClick?: () => void;
@@ -77,6 +84,7 @@ const TreeView = ({
7784
data = [],
7885
draggable = false,
7986
expandKeys: controlExpandKeys,
87+
activeKey: controlActiveKey,
8088
onExpand,
8189
onDropTree,
8290
onRightClick,
@@ -434,6 +442,10 @@ const TreeView = ({
434442
}
435443
}, [data]);
436444

445+
useEffect(() => {
446+
controlActiveKey && setActiveKey(controlActiveKey.toString());
447+
}, [controlActiveKey]);
448+
437449
return (
438450
<div
439451
role="tree"

src/workbench/sidebar/explore/folderTree.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ const FolderTree: React.FunctionComponent<IFolderTreeProps> = (props) => {
8282
...restProps
8383
} = props;
8484

85-
const { data = [], folderPanelContextMenu = [], expandKeys } = folderTree;
85+
const {
86+
data = [],
87+
folderPanelContextMenu = [],
88+
expandKeys,
89+
current,
90+
} = folderTree;
8691

8792
const handleAddRootFolder = () => {
8893
createTreeNode?.('RootFolder');
@@ -228,6 +233,7 @@ const FolderTree: React.FunctionComponent<IFolderTreeProps> = (props) => {
228233
<div data-content={panel.id} style={{ height: '100%' }}>
229234
<Tree
230235
// root folder do not render
236+
activeKey={current?.id}
231237
expandKeys={expandKeys}
232238
data={data[0]?.children || []}
233239
className={classNames(

0 commit comments

Comments
 (0)