Skip to content

Commit

Permalink
fix(Notification): update timer when timeout prop changes (#1673)
Browse files Browse the repository at this point in the history
  • Loading branch information
noook authored Apr 15, 2024
1 parent bbc8f4e commit cba9ad7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/runtime/components/overlays/Notification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</template>

<script lang="ts">
import { ref, computed, toRef, onMounted, onUnmounted, watchEffect, defineComponent } from 'vue'
import { ref, computed, toRef, onMounted, onUnmounted, watch, watchEffect, defineComponent } from 'vue'
import type { PropType } from 'vue'
import { twMerge, twJoin } from 'tailwind-merge'
import UIcon from '../elements/Icon.vue'
Expand Down Expand Up @@ -123,7 +123,7 @@ export default defineComponent({
setup (props, { emit }) {
const { ui, attrs } = useUI('notification', toRef(props, 'ui'), config)
let timer: any = null
let timer: null | ReturnType<typeof useTimer> = null
const remaining = ref(props.timeout)
const wrapperClass = computed(() => {
Expand Down Expand Up @@ -191,7 +191,11 @@ export default defineComponent({
emit('close')
}
onMounted(() => {
function initTimer () {
if (timer) {
timer.stop()
}
if (!props.timeout) {
return
}
Expand All @@ -203,7 +207,11 @@ export default defineComponent({
watchEffect(() => {
remaining.value = timer.remaining.value
})
})
}
watch(() => props.timeout, initTimer)
onMounted(initTimer)
onUnmounted(() => {
if (timer) {
Expand Down

0 comments on commit cba9ad7

Please sign in to comment.