From 1d6ea8df9990709cf1a2dd2abf5728085b589c3e Mon Sep 17 00:00:00 2001 From: WmW <48251883+nullptr-z@users.noreply.github.com> Date: Mon, 11 Apr 2022 15:52:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Tree):=20=E5=89=94=E9=99=A4=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E8=BF=87=E6=97=B6API=E5=BC=95=E7=94=A8=20#37?= =?UTF-8?q?4=20(#757)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/react-tree/src/TreeNode.tsx | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/react-tree/src/TreeNode.tsx b/packages/react-tree/src/TreeNode.tsx index 36c0e24ddb..ff66e0ee4b 100644 --- a/packages/react-tree/src/TreeNode.tsx +++ b/packages/react-tree/src/TreeNode.tsx @@ -49,26 +49,31 @@ export default function TreeNode(props: TreeNodeProps) { } = props; let isOpen = false; + const node = React.useRef(null); + if (parent && (parent.key || parent.key === 0)) { isOpen = !!(openKeys && openKeys.indexOf(parent.key) > -1); } - const onExit = useCallback((node: HTMLElement) => { - node.style.height = `${node.scrollHeight}px`; + + const onExit = useCallback(() => { + node.current!.style.height = `${node.current!.scrollHeight}px`; }, []); - const onExiting = useCallback((node: HTMLElement) => { - node.style.height = '1px'; + const onExiting = useCallback(() => { + node.current!.style.height = '1px'; }, []); - const onEnter = useCallback((node: HTMLElement, isAppearing: boolean) => { - node.style.height = '1px'; + const onEnter = useCallback(() => { + node.current!.style.height = '1px'; }, []); - const onEntering = useCallback((node: HTMLElement, isAppearing: boolean) => { - node.style.height = `${node.scrollHeight}px`; + const onEntering = useCallback(() => { + node.current!.style.height = `${node.current!.scrollHeight}px`; }, []); - const onEntered = useCallback((node: HTMLElement, isAppearing: boolean) => { - node.style.height = 'initial'; + const onEntered = useCallback(() => { + node.current!.style.height = 'initial'; }, []); + return ( (props: TreeNodeProps) { onEntering={onEntering} >