From 4a682ab00a86adba2d38b0da7f3eaf1a6208f647 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Sat, 7 May 2022 07:29:21 +0300 Subject: [PATCH] Toast: provide `isShown` method (#36272) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * feat(Toast): provide `isShown` method * Update site/content/docs/5.1/components/toasts.md Co-authored-by: Julien Déramond Co-authored-by: Julien Déramond --- js/src/toast.js | 8 ++++++-- site/content/docs/5.1/components/toasts.md | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/js/src/toast.js b/js/src/toast.js index b85e20b605..8ee8c8c968 100644 --- a/js/src/toast.js +++ b/js/src/toast.js @@ -100,7 +100,7 @@ class Toast extends BaseComponent { } hide() { - if (!this._element.classList.contains(CLASS_NAME_SHOW)) { + if (!this.isShown()) { return } @@ -123,13 +123,17 @@ class Toast extends BaseComponent { dispose() { this._clearTimeout() - if (this._element.classList.contains(CLASS_NAME_SHOW)) { + if (this.isShown()) { this._element.classList.remove(CLASS_NAME_SHOW) } super.dispose() } + isShown() { + return this._element.classList.contains(CLASS_NAME_SHOW) + } + // Private _maybeScheduleHide() { diff --git a/site/content/docs/5.1/components/toasts.md b/site/content/docs/5.1/components/toasts.md index e0750d5342..46f241cb3b 100644 --- a/site/content/docs/5.1/components/toasts.md +++ b/site/content/docs/5.1/components/toasts.md @@ -376,6 +376,7 @@ const toastList = [...toastElList].map(toastEl => new bootstrap.Toast(toastEl, o | --- | --- | | `show` | Reveals an element's toast. **Returns to the caller before the toast has actually been shown** (i.e. before the `shown.bs.toast` event occurs). You have to manually call this method, instead your toast won't show. | | `hide` | Hides an element's toast. **Returns to the caller before the toast has actually been hidden** (i.e. before the `hidden.bs.toast` event occurs). You have to manually call this method if you made `autohide` to `false`. | +| `isShown` | Returns a boolean according to toast's visibility state. | | `dispose` | Hides an element's toast. Your toast will remain on the DOM but won't show anymore. | | `getInstance` | *Static* method which allows you to get the scrollspy instance associated with a DOM element.
For example: `const myToastEl = document.getElementById('myToastEl')` `const myToast = bootstrap.Toast.getInstance(myToastEl)` Returns a Bootstrap toast instance| | `getOrCreateInstance` | *Static* method which allows you to get the scrollspy instance associated with a DOM element, or create a new one, in case it wasn't initialized.
`const myToastEl = document.getElementById('myToastEl')` `const myToast = bootstrap.Toast.getOrCreateInstance(myToastEl)` Returns a Bootstrap toast instance | -- 2.47.2