Skip to content

Commit

Permalink
fix(Modal): Wait for transition to complete to reset state
Browse files Browse the repository at this point in the history
  • Loading branch information
noook committed Apr 4, 2024
1 parent 4f0dc32 commit d37e274
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/runtime/components/overlays/Modal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<TransitionRoot :appear="appear" :show="isOpen" as="template">
<TransitionRoot :appear="appear" :show="isOpen" as="template" @after-leave="onAfterLeave">
<HDialog :class="ui.wrapper" v-bind="attrs" @close="close">
<TransitionChild v-if="overlay" as="template" :appear="appear" v-bind="ui.overlay.transition">
<div :class="[ui.overlay.base, ui.overlay.background]" />
Expand Down Expand Up @@ -82,7 +82,7 @@ export default defineComponent({
default: () => ({})
}
},
emits: ['update:modelValue', 'close', 'close-prevented'],
emits: ['update:modelValue', 'close', 'close-prevented', 'after-leave'],
setup (props, { emit }) {
const { ui, attrs } = useUI('modal', toRef(props, 'ui'), config, toRef(props, 'class'))
Expand Down Expand Up @@ -117,6 +117,10 @@ export default defineComponent({
emit('close')
}
const onAfterLeave = () => {
emit('after-leave')
}
provideUseId(() => useId())
return {
Expand All @@ -125,7 +129,8 @@ export default defineComponent({
attrs,
isOpen,
transitionClass,
close
onAfterLeave,
close,

Check failure on line 133 in src/runtime/components/overlays/Modal.vue

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 18)

Unexpected trailing comma
}
}
})
Expand Down
10 changes: 8 additions & 2 deletions src/runtime/components/overlays/Modals.client.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<template>
<component :is="modalState.component" v-if="modalState" v-bind="modalState.props" v-model="isOpen" />
<component
:is="modalState.component"
v-if="modalState"
v-bind="modalState.props"
v-model="isOpen"
@after-leave="reset"
/>
</template>

<script lang="ts" setup>
Expand All @@ -8,5 +14,5 @@ import { useModal, modalInjectionKey } from '../../composables/useModal'
const modalState = inject(modalInjectionKey)
const { isOpen } = useModal()
const { isOpen, reset } = useModal()
</script>
8 changes: 6 additions & 2 deletions src/runtime/composables/useModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ function _useModal () {
isOpen.value = true
}

function close () {
async function close () {
isOpen.value = false
}

function reset() {

Check failure on line 26 in src/runtime/composables/useModal.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 18)

Missing space before function parentheses
modalState.value = {
component: 'div',
props: {}
Expand All @@ -44,7 +47,8 @@ function _useModal () {
isOpen,
open,
close,
patch
reset,
patch,

Check failure on line 51 in src/runtime/composables/useModal.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 18)

Unexpected trailing comma
}
}

Expand Down

0 comments on commit d37e274

Please sign in to comment.