feat(VAlert): add timeout prop to auto-dismiss alerts#22947
Conversation
Add a `duration` prop that automatically dismisses the alert after the given time in milliseconds. A value of `0` (default) preserves the current behavior and never auto-dismisses. The timer restarts when the alert becomes visible or the duration changes, pauses while the alert is hovered or focused, and is cleared on manual close and on unmount — mirroring VSnackbar's timeout handling. resolves vuetifyjs#20409
7226b80 to
ddfea8d
Compare
|
On the prop name: I used |
|
On pausing: I copied the hover/focus handling from |
|
On reuse: I kept the timer inline rather than extracting a shared helper. |
|
On edge values: |
I think it would make sense. Including prop rename to |
Addresses review feedback on vuetifyjs#22947: - Rename the `VAlert` `duration` prop to `timeout` so it matches `VSnackbar` and avoids the cognitive load of two differently-named props with the same behavior. - Extract the auto-dismiss timeout and pause-on-hover/focus handling that was duplicated between `VSnackbar` and `VAlert` into a shared `useAutoDismiss` composable. `VSnackbar` keeps driving its visual countdown timer through the composable's `onStart`/`onClear` hooks. A `timeout` of `0` or less keeps the alert visible (default), so the behavior remains backwards compatible.
Addresses review feedback on vuetifyjs#22947: - Rename the `VAlert` `duration` prop to `timeout` so it matches `VSnackbar` and avoids the cognitive load of two differently-named props with the same behavior. - Extract the auto-dismiss timeout and pause-on-hover/focus handling that was duplicated between `VSnackbar` and `VAlert` into a shared `useAutoDismiss` composable. `VSnackbar` keeps driving its visual countdown timer through the composable's `onStart`/`onClear` hooks. A `timeout` of `0` or less keeps the alert visible (default), so the behavior remains backwards compatible.
712c742 to
b8a8f38
Compare
Addresses review feedback on vuetifyjs#22947: - Rename the `VAlert` `duration` prop to `timeout` so it matches `VSnackbar` and avoids the cognitive load of two differently-named props with the same behavior. - Extract the auto-dismiss timeout and pause-on-hover/focus handling that was duplicated between `VSnackbar` and `VAlert` into a shared `useAutoDismiss` composable. `VSnackbar` keeps driving its visual countdown timer through the composable's `onStart`/`onClear` hooks. The composable only treats a negative timeout as "never dismiss", so `VSnackbar` is unchanged (`-1` stays persistent, `0` still dismisses immediately). `VAlert` normalizes its `0` default to off, keeping it persistent by default and fully backwards compatible.
1e08331 to
2143c0e
Compare
Addresses review feedback on vuetifyjs#22947: - Rename the `VAlert` `duration` prop to `timeout` so it matches `VSnackbar` and avoids the cognitive load of two differently-named props with the same behavior. - Extract the auto-dismiss timeout and pause-on-hover/focus handling that was duplicated between `VSnackbar` and `VAlert` into a shared `useAutoDismiss` composable. `VSnackbar` keeps driving its visual countdown timer through the composable's `onStart`/`onClear` hooks. Both components now share the same `timeout` semantics: `-1` keeps the component visible indefinitely and `0` dismisses immediately. `VAlert` defaults to `-1`, so it stays persistent unless a timeout is set and remains backwards compatible. `VSnackbar` behavior is unchanged.
Document the new `timeout` prop on the alerts page with a runnable example, mirroring the existing `VSnackbar` timeout example.
2143c0e to
69b014d
Compare
|
@J-Sek updated. Renamed the prop to |
VSnackbar previously had no test coverage. Add browser tests for the timeout behavior now shared through `useAutoDismiss`: auto-dismiss after the timeout, pause while hovered, and stay open when the timeout is -1.
In headless CI the pointer rests at the top-left, over the full-width VAlert, which fires pointerenter and pauses its auto-dismiss timer, so the alert never closed (VSnackbar is unaffected since it renders away from the corner). Render the auto-dismiss alerts offset from the corner so their timer runs, and give the dismiss assertions a larger poll budget for slower CI.
28013e8 to
c603d04
Compare
Description
Adds a
timeoutprop toVAlertthat automatically dismisses the alert after a given time in milliseconds, matchingVSnackbar'stimeout. Currently developers have to wire up their ownsetTimeoutto hide an alert after a delay.timeoutaccepts a number (or numeric string) of milliseconds.-1(the default) keeps the alert visible indefinitely, so existing alerts are unaffected.0dismisses immediately and> 0dismisses after the given delay, matchingVSnackbar's semantics.timeoutchanges, and is cleared on manual close and on unmount.The auto-dismiss timeout and pause-on-hover/focus handling is shared with
VSnackbarthrough a newuseAutoDismisscomposable, so the two components stay consistent and the hover/focus pause logic that used to live only inVSnackbaris no longer duplicated. Pausing while hovered or focused also satisfies WCAG 2.2.1 (Timing Adjustable).VSnackbarkeeps driving its visual countdown timer through the composable'sonStart/onClearhooks, so its behavior is unchanged.Unit tests cover auto-dismiss, the pause-on-hover case, and the persistent default. The API description and a docs example have been added.
resolves #20409
Markup: