Skip to content

Commit

Permalink
refactor(Tree): 剔除组件中过时API引用 #374 (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
nullptr-z committed Apr 11, 2022
1 parent c05282f commit 1d6ea8d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/react-tree/src/TreeNode.tsx
Expand Up @@ -49,26 +49,31 @@ export default function TreeNode<T>(props: TreeNodeProps<T>) {
} = props;
let isOpen = false;

const node = React.useRef<HTMLUListElement>(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 (
<CSSTransition
nodeRef={node}
classNames={prefixCls}
in={isOpen}
timeout={200}
Expand All @@ -79,6 +84,7 @@ export default function TreeNode<T>(props: TreeNodeProps<T>) {
onEntering={onEntering}
>
<ul
ref={node}
className={[
level !== 1 && isOpen ? [`${prefixCls}-open`] : null,
level !== 1 && !isOpen ? [`${prefixCls}-close`] : null,
Expand Down

0 comments on commit 1d6ea8d

Please sign in to comment.