Skip to content

Commit ac938b8

Browse files
committed
fix(Popup): avoid repeatedly triggering updateScrollTop
1 parent c02237c commit ac938b8

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/components/popup/Popup.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const Popup = forwardRef<PopupInstanceFunctions, PopupProps>((originalProps, ref
9090
const portalRef = useRef(null); // portal dom 元素
9191
const contentRef = useRef<HTMLDivElement>(null); // 内容部分
9292
const popperRef = useRef<InnerPopperInstance>(null); // 保存 popper 实例
93+
const prevVisible = useRef(visible);
9394

9495
// 处理切换 panel 为 null 和正常内容动态切换的情况
9596
useEffect(() => {
@@ -214,12 +215,13 @@ const Popup = forwardRef<PopupInstanceFunctions, PopupProps>((originalProps, ref
214215

215216
// 下拉展开时更新内部滚动条和箭头位置
216217
useEffect(() => {
217-
if (visible && popupElement && contentRef.current) {
218-
requestAnimationFrame(() => {
218+
requestAnimationFrame(() => {
219+
prevVisible.current = visible;
220+
if (!prevVisible.current && visible && popupElement && contentRef.current) {
219221
updateScrollTop?.(contentRef.current);
220-
updateArrowPosition();
221-
});
222-
}
222+
}
223+
updateArrowPosition();
224+
});
223225
// eslint-disable-next-line react-hooks/exhaustive-deps
224226
}, [visible, content, popupElement]);
225227

packages/tdesign-react/CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ spline: explain
1717

1818
### 🐞 Bug Fixes
1919

20-
- `Cascader`:
21-
- 修复在弹出层可见期间,滚动位置被意外更新的问题 @RylanBot ([#4062](https://github.com/Tencent/tdesign-react/pull/4062))
22-
- 优化 Safari 浏览器中点击展开图标没有变换方向的问题 @liweijie0812 ([#4056](https://github.com/Tencent/tdesign-react/pull/4056))
20+
- `Cascader`: 优化 Safari 浏览器中点击展开图标没有变换方向的问题 @liweijie0812 ([#4056](https://github.com/Tencent/tdesign-react/pull/4056))
2321
- `Dialog`:
2422
- 修复 `closeOnOverlayClick``false` 时,`onOverlayClick` 无法触发的问题 @TidySongS ([#4065](https://github.com/Tencent/tdesign-react/pull/4065))
2523
- 修复 `mode="modeless"` 的弹窗,点击空白地方会被关闭的问题 @RylanBot ([#3950](https://github.com/Tencent/tdesign-react/pull/3950))

0 commit comments

Comments
 (0)