From 83f7c6ed4124257c08a30ab0ecb15b7f983b0896 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 30 Aug 2020 22:56:15 +0800 Subject: [PATCH] fix: modal afterClose trigger twice --- components/_util/PortalWrapper.js | 5 +++-- components/modal/Modal.jsx | 5 +++-- components/vc-dialog/Dialog.jsx | 11 ++--------- examples/App.vue | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/components/_util/PortalWrapper.js b/components/_util/PortalWrapper.js index 2ae3f6b29..84170c206 100644 --- a/components/_util/PortalWrapper.js +++ b/components/_util/PortalWrapper.js @@ -2,6 +2,7 @@ import PropTypes from './vue-types'; import switchScrollingEffect from './switchScrollingEffect'; import setStyle from './setStyle'; import Portal from './Portal'; +import syncWatch from './syncWatch'; let openCount = 0; const windowIsUndefined = !( @@ -32,9 +33,9 @@ export default { this.setWrapperClassName(); }, watch: { - visible(val) { + visible: syncWatch(function(val) { openCount = val ? openCount + 1 : openCount - 1; - }, + }), getContainer(getContainer, prevGetContainer) { const getContainerIsFunc = typeof getContainer === 'function' && typeof prevGetContainer === 'function'; diff --git a/components/modal/Modal.jsx b/components/modal/Modal.jsx index 8423f638e..7808322f3 100644 --- a/components/modal/Modal.jsx +++ b/components/modal/Modal.jsx @@ -11,6 +11,7 @@ const ButtonType = buttonTypes().type; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import { initDefaultProps, getComponent, getSlot } from '../_util/props-util'; import { ConfigConsumerProps } from '../config-provider'; +import syncWatch from '../_util/syncWatch'; let mousePosition = null; // ref: https://github.com/ant-design/ant-design/issues/15795 @@ -106,9 +107,9 @@ export default { }; }, watch: { - visible(val) { + visible: syncWatch(function(val) { this.sVisible = val; - }, + }), }, setup() { return { diff --git a/components/vc-dialog/Dialog.jsx b/components/vc-dialog/Dialog.jsx index 13273931b..420fcacb3 100644 --- a/components/vc-dialog/Dialog.jsx +++ b/components/vc-dialog/Dialog.jsx @@ -65,7 +65,6 @@ export default { }), data() { return { - destroyPopup: false, inTransition: false, titleId: `rcDialogTitle${uuid++}`, dialogMouseDown: undefined, @@ -74,9 +73,6 @@ export default { watch: { visible(val) { - if (val) { - this.destroyPopup = false; - } this.$nextTick(() => { this.updatedCallback(!val); }); @@ -147,15 +143,12 @@ export default { } }, onAnimateLeave() { - const { afterClose, destroyOnClose } = this; + const { afterClose } = this; // need demo? // https://github.com/react-component/dialog/pull/28 if (this.$refs.wrap) { this.$refs.wrap.style.display = 'none'; } - if (destroyOnClose) { - this.destroyPopup = true; - } this.inTransition = false; this.switchScrollingEffect(); if (afterClose) { @@ -295,7 +288,7 @@ export default { }); return ( - {visible || !this.destroyPopup ? dialogElement : null} + {visible || !this.destroyOnClose ? dialogElement : null} ); }, diff --git a/examples/App.vue b/examples/App.vue index d41d93abc..29646cb81 100644 --- a/examples/App.vue +++ b/examples/App.vue @@ -15,7 +15,7 @@ Use Drawer to quickly preview details of an object, such as those in a list.