iamhosseindhv / notistack

Highly customizable notification snackbars (toasts) that can be stacked on top of each other
https://notistack.com
Other
3.93k stars 298 forks source link

Please remove timer pause on 'interaction' #516

Open fabyeah opened 2 years ago

fabyeah commented 2 years ago

Currently the auto hide timer of the snackbar pauses when a user interacts with a snackbar and resets when the user stops interacting.

    /**
     * Pause the timer when the user is interacting with the Snackbar
     * or when the user hide the window.
     */
    const handlePause = () => {
        clearTimeout(timerAutoHide.current);
    };

I'd argue that this is detrimental behavior. I don't see many use cases where this behavior is expected or helpful except maybe when someone is selecting and copying text from the snackbar. The much more frequent action of pressing a button only takes a fraction of a second and doesn't require a timeout imho. If it is necessary to pause the timer, that just means the developer failed in allotting enough time or keeping the text short and simple. Also moving the mouse into the snackbar on desktop or tapping it on mobile is not an intuitive action that users know and understand will stop the bar from disappearing.

On the other hand this feature is cause to frequent irritation of my users, as on mobile users will often try to swipe away purely informational snackbars without action buttons and then realize that that doesn't work (feature not implemented yet: https://github.com/iamhosseindhv/notistack/issues/281, https://github.com/iamhosseindhv/notistack/issues/138), and worse: the snackbar now for some reason doesn't disappear (until they tap outside, but often they will only scroll, which doesn't reset the timer). https://github.com/iamhosseindhv/notistack/issues/422 As the swiping away of notifications is an instinctual gesture, most affected users will not make the connection and just wonder why sometimes the snackbars go away and sometimes they stay around forever.

To fix this, I would suggest to simply remove the pause mechanism.

fabyeah commented 2 years ago

Even just an option to disable the feature would be helpful 🙏

iamhosseindhv commented 2 years ago

What version of notistack are you using @fabyeah ? v2 or v3? I can publish an update to v3

fabyeah commented 2 years ago

I'm using v2.

But an update to v3 is better than nothing, guess I could upgrade.

david-vendel commented 1 year ago

I also need this exact functionality removed or the ability to disable it. Thank you.

david-vendel commented 1 year ago

For anyone having same need, this is possible bypass:

/**
 * Custom hook which overrides default functionality to pause snackbar close timer when mouse is hovered over it, by ignoring the mouse.
 */
export const useSnackbar = () => {
  const { enqueueSnackbar: enqueueSnackbarFn } = useSnackbarFn()

  const enqueueSnackbar = (message: string, options: OptionsObject) => {
    const snackbarOptions = options || {}

    snackbarOptions.SnackbarProps = {
      ...snackbarOptions.SnackbarProps,
      style: { pointerEvents: 'none' },
    }

    enqueueSnackbarFn(message, snackbarOptions)
  }

  return { enqueueSnackbar }
}

However this doesn't solve snackbar staying on page forever when web broser is de-focused.

Bonfims commented 1 year ago

how can i prevent snackbar staying forever when web broser is de-focused?

iamhosseindhv commented 1 year ago

@Bonfims

how can i prevent snackbar staying forever when web broser is de-focused?

You can use the disableWindowBlurListener flag. See api reference