apvarun / toastify-js

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

External close Toast - dismiss toast #91

Open Shaka-60hp opened 2 years ago

Shaka-60hp commented 2 years ago

Hi, first of all thank you guys I wonder if there is a way or function to dismiss the toas from outside the toast, like the close button but external to th toast

If there is, please add the function to the documentation and some example if posible Thanks !!

pavlexander commented 2 years ago

I would also like something similar.. I was wondering if you could close the toast by clicking on it? (as opposed to waiting for it to close automatically or clicking on a small close button).

I tried doing the following:

      Toastify({
        text: "This is a toast",
        duration: 2000,
        close: false,
        stopOnFocus: true,
        onClick: function () {
          this.dismiss();
          this.hide();
          this.hideToast();
          this.destroy();
          this.close();
          this.dispose();
        },
      }).showToast();

but there is no dismiss function, no hide/hideToast/destroy/close/dispose (like OP wants as well). If the function was there then the OP could probably reference the instance and call the method on it.. In my case I just want the toast the close on click...

pavlexander commented 2 years ago

nvm I figured it out

      var toast = Toastify({
        text: "This is a toast",
        duration: 2000,
        close: false,
        stopOnFocus: true,
        onClick: function () {
          toast.hideToast();
        },
      });

      toast.showToast();

so just keep the toast reference and invoke the toast.hideToast(); when you want it to be closed.