From 2cbe9b131aaba0ab3266854aec9cc017802856f1 Mon Sep 17 00:00:00 2001 From: Rohit Sharma Date: Sun, 12 Jul 2020 00:21:04 +0530 Subject: [PATCH] Clear timeout before showing the toast (#31155) * clear timeout before showing the toast * Add unit test * Remove the check for timeout * Check for clearTimeout to have been called Co-authored-by: XhmikosR # Conflicts: # js/tests/unit/toast.spec.js --- js/src/toast.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/src/toast.js b/js/src/toast.js index 8da5069e9642..937776833111 100644 --- a/js/src/toast.js +++ b/js/src/toast.js @@ -83,6 +83,8 @@ class Toast { return } + this._clearTimeout() + if (this._config.animation) { this._element.classList.add(CLASS_NAME_FADE) } @@ -130,8 +132,7 @@ class Toast { } dispose() { - clearTimeout(this._timeout) - this._timeout = null + this._clearTimeout() if (this._element.classList.contains(CLASS_NAME_SHOW)) { this._element.classList.remove(CLASS_NAME_SHOW) @@ -184,6 +185,11 @@ class Toast { } } + _clearTimeout() { + clearTimeout(this._timeout) + this._timeout = null + } + // Static static _jQueryInterface(config) {