Skip to content

Commit dacf608

Browse files
uyarntdesign-bot
andauthored
fix(Tree): remove leftover delay when transition is disabled (#4231)
* fix(Tree): remove leftover delay when collapsing nodes with transition disabled * chore: stash changelog [ci skip] --------- Co-authored-by: tdesign-bot <tdesign@tencent.com>
1 parent 6f48c83 commit dacf608

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

packages/components/tree/Tree.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ import type { TdTreeProps, TreeInstanceFunctions } from './type';
3939
export type TreeProps = TdTreeProps & StyledProps;
4040

4141
const Tree = forwardRef<TreeInstanceFunctions<TreeOptionData>, TreeProps>((originalProps, ref) => {
42-
const { treeClassNames, transitionNames, transitionClassNames, transitionDuration, locale } = useTreeConfig();
43-
4442
const { value, onChange, expanded, onExpand, onActive, actived, setTreeIndeterminate, indeterminate } =
4543
useControllable(originalProps);
4644
const props = useDefaultProps<TreeProps>(originalProps, treeDefaultProps);
@@ -66,6 +64,9 @@ const Tree = forwardRef<TreeInstanceFunctions<TreeOptionData>, TreeProps>((origi
6664
onScroll,
6765
} = props;
6866

67+
const { treeClassNames, transitionNames, transitionClassNames, transitionDuration, locale } =
68+
useTreeConfig(transition);
69+
6970
// 可见节点集合
7071
const [visibleNodes, setVisibleNodes] = useState([]);
7172

packages/components/tree/hooks/useTreeConfig.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useMemo } from 'react';
22
import useConfig from '../../hooks/useConfig';
33
import { useLocaleReceiver } from '../../locale/LocalReceiver';
44

5-
export function useTreeConfig() {
5+
export function useTreeConfig(transition = true) {
66
const { classPrefix: prefix } = useConfig();
77
const [locale, t] = useLocaleReceiver('tree');
88

@@ -63,8 +63,9 @@ export function useTreeConfig() {
6363
treeClassNames,
6464
transitionNames,
6565
transitionClassNames,
66-
transitionDuration: 300,
66+
// transition 关闭时立即移除节点,避免 CSSTransition 多等 300ms 造成的关闭延迟
67+
transitionDuration: transition ? 300 : 0,
6768
locale: (key) => t(locale[key]),
6869
};
69-
}, [locale, prefix, t]);
70+
}, [locale, prefix, t, transition]);
7071
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 4231
3+
contributor: uyarn
4+
---
5+
6+
- fix(Tree): 修复关闭 `transition` API 后,由于内部 duration 没有移除导致出现的卡顿表现 @uyarn ([#4231](https://github.com/Tencent/tdesign-react/pull/4231))

0 commit comments

Comments
 (0)