Prevent toast close with mobile swipe

17 Feb 20222 minutes to read

You can prevent the toast close with mobile swipe action by setting beforeClose argument cancel value to true while argument type is swipe. The following code shows how to prevent toast close with mobile swipe.

The following sample demonstrates preventing toast close with mobile swipe element displaying with custom code blocks.

<div class="control-section" style="width:400px;margin:0 auto;">
    <ejs-toast id="element" title="Matt sent you a friend request" content="You have a new friend request yet to accept" beforeClose="beforeClose"></ejs-toast>
    <ejs-button id="button" content="Show Toast" cssClass="e-btn"></ejs-button>
<script type="text/javascript">
        () => {
            var toastObj = document.getElementById('element').ej2_instances[0];
   = document.body;
        }, 1000);
    document.getElementById("button").addEventListener('click', function () {
        var toastObj = document.getElementById('element').ej2_instances[0];;
    function beforeClose(args: ToastBeforeCloseArgs){
        if (args.type === "swipe") {
            args.cancel = true;
public class HomeController : Controller

    public ActionResult Index()
        return View();