Skip to content

Commit

Permalink
fix: use activeKey to control highlighting (#724) (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaoei authored May 25, 2022
1 parent 22f310f commit 52d79b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/components/tree/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -77,6 +84,7 @@ const TreeView = ({
data = [],
draggable = false,
expandKeys: controlExpandKeys,
activeKey: controlActiveKey,
onExpand,
onDropTree,
onRightClick,
Expand Down Expand Up @@ -434,6 +442,10 @@ const TreeView = ({
}
}, [data]);

useEffect(() => {
controlActiveKey && setActiveKey(controlActiveKey.toString());
}, [controlActiveKey]);

return (
<div
role="tree"
Expand Down
8 changes: 7 additions & 1 deletion src/workbench/sidebar/explore/folderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ const FolderTree: React.FunctionComponent<IFolderTreeProps> = (props) => {
...restProps
} = props;

const { data = [], folderPanelContextMenu = [], expandKeys } = folderTree;
const {
data = [],
folderPanelContextMenu = [],
expandKeys,
current,
} = folderTree;

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

0 comments on commit 52d79b0

Please sign in to comment.