question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tapToDismiss ignored when onclick is set

See original GitHub issue

Hello,

I’m trying to display a toast with the property tapToDismiss set to false

toastr.info('title', 'message', {
tapToDismiss: false, 
closeButton: true, 
timeOut: 0, 
extendedTimeOut: 0, 
});

This works well but if I add a onclick handler, the toast closes when I click it.

toastr.info('title', 'message', {
tapToDismiss: false, 
closeButton: true, 
timeOut: 0, 
extendedTimeOut: 0, 
onclick: function(){
    alert('click');
}
});

Currently, I’ve found a workaround by adding the click handler on the elem returned by the info method but I think there is a little bug here…

var toast = toastr.info('title', 'message', {
tapToDismiss: false, 
closeButton: true, 
timeOut: 0, 
extendedTimeOut: 0, 
});
toast.on('click', function(){
    alert('click');
});

Thanks

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RiCKecommented, Oct 23, 2014

For the moment, I use the workaround shown in my third exemple. But i think this bug comes from line 297 in toastr.js

if (options.onclick) {
    $toastElement.click(function () {
        options.onclick();
        hideToast();
    });
}

Just add a check of tapToDismiss property before calling hideToast and it will do the trick

if (options.onclick) {
    $toastElement.click(function () {
        options.onclick();
        if(options.tapToDismiss){
            hideToast();
        }
    });
}
0reactions
raquelrochacommented, Dec 17, 2018

I’m having this problem again, and i’ve checked toastr.js and somehow the change made here no longer exists:

if (options.onclick) {
   $toastElement.click(function (event) {
           options.onclick(event);
           hideToast();
    });
}

If it is meant to be this way, then please guide me to a workaround to this behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

My onclick event is being ignored - javascript - Stack Overflow
The code that I've tried is below. The only thing that doesn't work is the onclick event. <a onClick="ga('set', 'nonInteraction' ...
Read more >
Browser default actions - The Modern JavaScript Tutorial
The value returned by an event handler is usually ignored. The only exception is return false from a handler assigned using on<event> ....
Read more >
https://raw.githubusercontent.com/DefinitelyTyped/...
tapToDismiss ?: boolean; /** * CSS class the toast element will be given ... than having identical toasts stack, set the preventDuplicates property...
Read more >
angular2-toaster - npm
By default, the tapToDismiss option is set to true, meaning that if a toast is clicked anywhere on the toast body, the toast...
Read more >
toastr.show() Code Example - Code Grepper
tapToDismiss :true, ... set timeOut and extendedTimeOut to 0 to make it sticky ... composer install ignore · Ignore platform version laravel ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found