From 3cc2763ec7638a3018f3d01ce491c22935eb67c2 Mon Sep 17 00:00:00 2001 From: Kael Date: Tue, 30 Jul 2024 15:48:55 +1000 Subject: [PATCH] fix(VSnackbar): update countdown value on timeout change fixes #20196 --- .../vuetify/src/components/VSnackbar/VSnackbar.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/vuetify/src/components/VSnackbar/VSnackbar.tsx b/packages/vuetify/src/components/VSnackbar/VSnackbar.tsx index 600414a1777..1e4bae621e0 100644 --- a/packages/vuetify/src/components/VSnackbar/VSnackbar.tsx +++ b/packages/vuetify/src/components/VSnackbar/VSnackbar.tsx @@ -34,8 +34,8 @@ type VSnackbarSlots = { text: never } -function useCountdown (milliseconds: number) { - const time = shallowRef(milliseconds) +function useCountdown (milliseconds: () => number) { + const time = shallowRef(milliseconds()) let timer = -1 function clear () { @@ -45,7 +45,7 @@ function useCountdown (milliseconds: number) { function reset () { clear() - nextTick(() => time.value = milliseconds) + nextTick(() => time.value = milliseconds()) } function start (el?: HTMLElement) { @@ -59,7 +59,7 @@ function useCountdown (milliseconds: number) { const startTime = performance.now() timer = window.setInterval(() => { const elapsed = performance.now() - startTime + interval - time.value = Math.max(milliseconds - elapsed, 0) + time.value = Math.max(milliseconds() - elapsed, 0) if (time.value <= 0) clear() }, interval) @@ -106,7 +106,7 @@ export const VSnackbar = genericComponent()({ const { themeClasses } = provideTheme(props) const { colorClasses, colorStyles, variantClasses } = useVariant(props) const { roundedClasses } = useRounded(props) - const countdown = useCountdown(Number(props.timeout)) + const countdown = useCountdown(() => Number(props.timeout)) const overlay = ref() const timerRef = ref()