Skip to content

Commit a426b62

Browse files
fix(Dialog): allow overlay click callback when close disabled (#4065)
* fix(dialog): allow overlay click callback when close disabled * chore: stash changelog [ci skip] --------- Co-authored-by: tdesign-bot <tdesign@tencent.com>
1 parent fafc747 commit a426b62

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

packages/components/dialog/Dialog.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,18 @@ const Dialog = forwardRef<DialogInstance, DialogProps>((originalProps, ref) => {
150150
}
151151

152152
const onMaskClick = (e: React.MouseEvent<HTMLDivElement>) => {
153-
if (showOverlay && (closeOnOverlayClick ?? local.closeOnOverlayClick)) {
154-
// 判断点击事件初次点击是否为内容区域
155-
if (contentClickRef.current) {
156-
contentClickRef.current = false;
157-
} else if (e.target === dialogPosition.current) {
158-
onOverlayClick?.({ e });
159-
onClose?.({ e, trigger: 'overlay' });
160-
}
153+
if (!showOverlay) return;
154+
// 判断点击事件初次点击是否为内容区域
155+
if (contentClickRef.current) {
156+
contentClickRef.current = false;
157+
return;
158+
}
159+
if (e.target !== dialogPosition.current) return;
160+
// 触发蒙层点击事件
161+
onOverlayClick?.({ e });
162+
// 触发关闭事件
163+
if (closeOnOverlayClick ?? local.closeOnOverlayClick) {
164+
onClose?.({ e, trigger: 'overlay' });
161165
}
162166
};
163167

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 4065
3+
contributor: TidySongS
4+
---
5+
6+
- fix(Dialog): 修复 `closeOnOverlayClick``false` 时,`onOverlayClick` 无法触发的问题 @TidySongS ([#4065](https://github.com/Tencent/tdesign-react/pull/4065))

0 commit comments

Comments
 (0)