apvarun / toastify-js

Pure JavaScript library for better notification messages
https://apvarun.github.io/toastify-js/
MIT License
2.21k stars 233 forks source link

Close / dismiss on click? #53

Closed dessalines closed 4 years ago

dessalines commented 4 years ago

Is there any way to close / dismiss on click?

apvarun commented 4 years ago

Yes, you can dismiss a toast on click using the onClick parameter. Example: https://codesandbox.io/s/toastify-js-issues-53-2gi84

@dessalines Does this solve your use case?

dessalines commented 4 years ago

That did it, thanks!

It might be good to document the methods somewhere, I couldn't find hideToast() anywhere in the docs / README.

Putting the solution here:

const dismissableToast = Toastify({
  text: "Dismiss on Click",
  duration: 5000,
  stopOnFocus: true,
  onClick: function() {
    if (dismissableToast) {
      dismissableToast.hideToast();
    }
  }
}).showToast();