Skip to content

Commit

Permalink
fix(comp:modal): destroyOnHide cause can't drag
Browse files Browse the repository at this point in the history
  • Loading branch information
kovsu committed Mar 27, 2023
1 parent 703122f commit 935b176
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/components/modal/src/ModalProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { ModalInstance, ModalOptions, ModalRef } from './types'
import type { VKey } from '@idux/cdk/utils'
import type { MaybeArray, VKey } from '@idux/cdk/utils'

import { cloneVNode, defineComponent, isVNode, provide, shallowRef } from 'vue'

Expand All @@ -28,12 +28,19 @@ export default defineComponent({
return () => {
const children = modals.value.map(item => {
// The default value for `visible`, onDestroy should not be passed in Modal
const { key, visible = true, destroyOnHide, onDestroy, content, contentProps, ...restProps } = item
const { key, visible = true, destroyOnHide, onDestroy, content, contentProps, onOk, ...restProps } = item
const setRef = (instance: unknown) => setModalRef(key!, instance as ModalInstance | null)
const onUpdateVisible = (visible: boolean) => update(key!, { visible })
const onAfterClose = destroyOnHide ? () => destroy(key!) : undefined
const mergedProps = { key, visible, ref: setRef, 'onUpdate:visible': onUpdateVisible, onAfterClose }
const _onOk: MaybeArray<(evt?: unknown) => unknown> = []

if (destroyOnHide) {
_onOk.push(() => destroy(key!))
}
if (onOk) {
Array.isArray(onOk) ? _onOk.unshift(...onOk) : _onOk.unshift(onOk)
}

const mergedProps = { key, visible, ref: setRef, 'onUpdate:visible': onUpdateVisible, onOk: _onOk }
const contentNode = isVNode(content) ? cloneVNode(content, contentProps, true) : content
return <Modal {...mergedProps} {...restProps} __content_node={contentNode} />
})
Expand Down

0 comments on commit 935b176

Please sign in to comment.