Skip to content

Commit 1d6ea8d

Browse files
authoredApr 11, 2022
refactor(Tree): 剔除组件中过时API引用 #374 (#757)
1 parent c05282f commit 1d6ea8d

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed
 

‎packages/react-tree/src/TreeNode.tsx

+16-10
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,31 @@ export default function TreeNode<T>(props: TreeNodeProps<T>) {
4949
} = props;
5050
let isOpen = false;
5151

52+
const node = React.useRef<HTMLUListElement>(null);
53+
5254
if (parent && (parent.key || parent.key === 0)) {
5355
isOpen = !!(openKeys && openKeys.indexOf(parent.key) > -1);
5456
}
55-
const onExit = useCallback((node: HTMLElement) => {
56-
node.style.height = `${node.scrollHeight}px`;
57+
58+
const onExit = useCallback(() => {
59+
node.current!.style.height = `${node.current!.scrollHeight}px`;
5760
}, []);
58-
const onExiting = useCallback((node: HTMLElement) => {
59-
node.style.height = '1px';
61+
const onExiting = useCallback(() => {
62+
node.current!.style.height = '1px';
6063
}, []);
61-
const onEnter = useCallback((node: HTMLElement, isAppearing: boolean) => {
62-
node.style.height = '1px';
64+
const onEnter = useCallback(() => {
65+
node.current!.style.height = '1px';
6366
}, []);
64-
const onEntering = useCallback((node: HTMLElement, isAppearing: boolean) => {
65-
node.style.height = `${node.scrollHeight}px`;
67+
const onEntering = useCallback(() => {
68+
node.current!.style.height = `${node.current!.scrollHeight}px`;
6669
}, []);
67-
const onEntered = useCallback((node: HTMLElement, isAppearing: boolean) => {
68-
node.style.height = 'initial';
70+
const onEntered = useCallback(() => {
71+
node.current!.style.height = 'initial';
6972
}, []);
73+
7074
return (
7175
<CSSTransition
76+
nodeRef={node}
7277
classNames={prefixCls}
7378
in={isOpen}
7479
timeout={200}
@@ -79,6 +84,7 @@ export default function TreeNode<T>(props: TreeNodeProps<T>) {
7984
onEntering={onEntering}
8085
>
8186
<ul
87+
ref={node}
8288
className={[
8389
level !== 1 && isOpen ? [`${prefixCls}-open`] : null,
8490
level !== 1 && !isOpen ? [`${prefixCls}-close`] : null,

0 commit comments

Comments
 (0)
Please sign in to comment.