Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(comp:modal): fix loading stop before hide #961

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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