Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Ability to pause timeout when actively hovering/mousing over the toast #148

Closed
avisra opened this issue Oct 29, 2021 · 4 comments · Fixed by #203
Closed
Labels
Feature Request Request to add a new feature

Comments

@avisra
Copy link

avisra commented Oct 29, 2021

Is your feature request related to a problem? Please describe.
Let's assume the toast message requires taking action - like clicking a button, or copying some text out from it. Depending on the speed of the user, it is a common complaint that the toast closes before they can complete the action.

Describe the solution you'd like
Similar to the react-toastify library, I recommend we add a "pauseOnHover" option which enables this feature. When a user's mouse is actively hovering over a toast message, the timeout should be paused, and the progress bar should be paused.

Describe alternatives you've considered
We've considered just increasing the timeout... but this is not desirable

@avisra avisra added Feature Request Request to add a new feature Triage Issue needs to be triaged labels Oct 29, 2021
@chrissainty
Copy link
Member

Hi @avisra, this sounds like a great enhancement. Is this something you're be willing to create a PR for?

@hellfirehd
Copy link

In addition to this, it would be great if the toast would immediately fade out upon mouse out.

@Liero
Copy link

Liero commented Jan 3, 2022

@hellfirehd: "immediately fade out upon mouse out" - In my own toast notifications library I have a ExtendedTimeout option, which is used toastr as well: https://codeseven.github.io/toastr/demo.html

basically you can configure the delay between mouse out and and fade out.

@chrissainty chrissainty removed the Triage Issue needs to be triaged label Feb 13, 2023
@Cvijo
Copy link
Contributor

Cvijo commented Feb 13, 2023

This should be pretty easy to add, I don't know how to propose this to implement but something like this would work so if someone can check it and merge it with the next build

in ToastSettings.cs add

public bool PauseProgressOnHover { get; set; }

in BlatoredToast.razor.cs add

    private void MouseOver(MouseEventArgs e)
    {
        if(Settings.PauseProgressOnHover)
        {
            _countdownTimer?.Pause();
        }
    }

    private void MouseOut(MouseEventArgs e)
    {
        if (Settings.PauseProgressOnHover)
        {
            _progress = 99; // for 1 sec close after mouse out (request = In addition to this, it would be great if the toast would immediately fade out upon mouse out.)
            _countdownTimer?.UnPause();
        }
    }

in Blazored.razor add

<div class="blazored-toast @Settings.AdditionalClasses" @onclick="ToastClick" @onmouseover="MouseOver" @onmouseout="MouseOut">

in CountdownTimes.cs

private bool _paused;

 internal CountdownTimer Pause()
 {
     _paused = true;
     return this;
 }

 internal CountdownTimer UnPause()
 {
     _paused = false;
     return this;
 }


private async Task DoWorkAsync()
 {
     while (await _timer.WaitForNextTickAsync(_cancellationToken) && !_cancellationToken.IsCancellationRequested)
     {
         if (!_paused) //only progress if not paused
         {
             _percentComplete++;
         }
         if (_tickDelegate != null)
         {
             await _tickDelegate(_percentComplete);
         }
         //await _tickDelegate?.Invoke(_percentComplete)!;

         if (_percentComplete == _ticksToTimeout)
         {
             _elapsedDelegate?.Invoke();
         }
     }
 }

maybe add another property if AutoCloseOnMouseOut and then set _progress=99 before Unpause (better to stay up 1 more sec) or just call _timer.Dispose()

This can have max 1 sec delay on pausing since ticking is every 1 sec

Cvijo pushed a commit to Cvijo/Toast that referenced this issue Feb 14, 2023
Cvijo pushed a commit to Cvijo/Toast that referenced this issue Feb 14, 2023
This reverts commit e27f67d.
Cvijo pushed a commit to Cvijo/Toast that referenced this issue Feb 14, 2023
Cvijo pushed a commit to Cvijo/Toast that referenced this issue Feb 14, 2023
Cvijo pushed a commit to Cvijo/Toast that referenced this issue Feb 21, 2023
chrissainty pushed a commit that referenced this issue Feb 23, 2023
Cvijo added a commit to Cvijo/Toast that referenced this issue Feb 23, 2023
chrissainty added a commit that referenced this issue Feb 23, 2023
* added ability to use toast position on each toast instance instead of single global position

* - passing additinal css classes to toast (#207)

* Pause on hover feature #148 (#203)

---------

Co-authored-by: Matija Gluhak <matija.gluhak@vipdata.hr>
Co-authored-by: Chris Sainty <chrissainty@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Request to add a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants