diff --git a/.changeset/brown-mails-accept.md b/.changeset/brown-mails-accept.md new file mode 100644 index 000000000..d35b72803 --- /dev/null +++ b/.changeset/brown-mails-accept.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/pop-confirm": patch +--- + +fix: 修复点击按钮会触发 onCancel 问题 diff --git a/.changeset/fast-waves-explode.md b/.changeset/fast-waves-explode.md new file mode 100644 index 000000000..b918a14ca --- /dev/null +++ b/.changeset/fast-waves-explode.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/hiui": patch +--- + +fix(pop-confirm): 修复点击确定按钮会触发 onCancel 问题 diff --git a/packages/ui/pop-confirm/src/use-pop-confirm.ts b/packages/ui/pop-confirm/src/use-pop-confirm.ts index 272ae49fa..1a28cd324 100644 --- a/packages/ui/pop-confirm/src/use-pop-confirm.ts +++ b/packages/ui/pop-confirm/src/use-pop-confirm.ts @@ -23,17 +23,17 @@ export const usePopConfirm = ({ defaultVisible: false, visible: visibleProp, onOpen, - onClose: () => { - onClose?.() - onCancelProp?.() - }, + onClose, }) + const onCancelLatest = useLatestCallback(onCancelProp) + const onCancel = useCallback(() => { + onCancelLatest() if (closeOnCancel) { visibleAction.off() } - }, [closeOnCancel, visibleAction]) + }, [closeOnCancel, visibleAction, onCancelLatest]) const onConfirmLatest = useLatestCallback(onConfirmProp)