Skip to content

Commit

Permalink
fix(comp:modal): fix loading stop before hide (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingshan-dev authored Jun 16, 2022
1 parent 6b36b31 commit 8f3f696
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/components/modal/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ function useScrollStrategy(props: ModalProps, mask: ComputedRef<boolean>, merged

function useTrigger(props: ModalProps, setVisible: (value: boolean) => void) {
const open = () => setVisible(true)
const hide = (result: boolean | unknown) => {
result !== false && setVisible(false)
}

const close = async (evt?: Event | unknown) => {
const result = await callEmit(props.onBeforeClose, evt)
if (result === false) {
return
}
setVisible(false)
callEmit(props.onClose, evt)
hide(result)
result !== false && callEmit(props.onClose, evt)
}

const cancelLoading = ref(false)
Expand All @@ -131,12 +131,11 @@ function useTrigger(props: ModalProps, setVisible: (value: boolean) => void) {
if (isPromise(result)) {
cancelLoading.value = true
result = await result
hide(result)
cancelLoading.value = false
}
if (result === false) {
return
}
setVisible(false)
hide(result)
}

const okLoading = ref(false)
Expand All @@ -145,12 +144,11 @@ function useTrigger(props: ModalProps, setVisible: (value: boolean) => void) {
if (isPromise(result)) {
okLoading.value = true
result = await result
hide(result)
okLoading.value = false
}
if (result === false) {
return
}
setVisible(false)
hide(result)
}

return { cancelLoading, okLoading, open, close, cancel, ok }
Expand Down

0 comments on commit 8f3f696

Please sign in to comment.