Skip to content

Commit

Permalink
feat(Toast): provide isShown method
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed May 3, 2022
1 parent 51535cd commit c5370cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/src/toast.js
Expand Up @@ -100,7 +100,7 @@ class Toast extends BaseComponent {
}

hide() {
if (!this._element.classList.contains(CLASS_NAME_SHOW)) {
if (!this.isShown()) {
return
}

Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions site/content/docs/5.1/components/toasts.md
Expand Up @@ -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`. |
| `isShow` | 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. <br> 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. <br>`const myToastEl = document.getElementById('myToastEl')` `const myToast = bootstrap.Toast.getOrCreateInstance(myToastEl)` Returns a Bootstrap toast instance |
Expand Down

0 comments on commit c5370cc

Please sign in to comment.