Skip to content

Commit

Permalink
fix(VSnackbar): update countdown value on timeout change
Browse files Browse the repository at this point in the history
fixes #20196
  • Loading branch information
KaelWD committed Jul 30, 2024
1 parent 3a31086 commit 3cc2763
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/vuetify/src/components/VSnackbar/VSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -45,7 +45,7 @@ function useCountdown (milliseconds: number) {
function reset () {
clear()

nextTick(() => time.value = milliseconds)
nextTick(() => time.value = milliseconds())
}

function start (el?: HTMLElement) {
Expand All @@ -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)
Expand Down Expand Up @@ -106,7 +106,7 @@ export const VSnackbar = genericComponent<VSnackbarSlots>()({
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<VOverlay>()
const timerRef = ref<VProgressLinear>()
Expand Down

0 comments on commit 3cc2763

Please sign in to comment.