New Toast.isShown() method
Created by: khalyomede
Prerequisites
-
I have searched for duplicate or closed feature requests -
I have read the contributing guidelines
Proposal
import { Toast } from "bootstrap";
const element = document.getElementById("toast");
if (element instanceof HTMLElement) {
const toast = new Toast(element);
// Before
if (!element.classList.contains("show")) {
toast.show();
}
// after
if (!toast.isShown()) {
toast.show();
}
}
Motivation and context
I would like to prevent the user to see new animation of the toast if he clicks multiple time to show the same toast.
I do not know how to import the "CLASS_NAME_SHOW" (https://github.com/twbs/bootstrap/blob/main/js/src/toast.js#L32) constant, and it feels like this is not safe to rely on the "show" class name.
On the other hand, having a Toast.isShown()
method would ensure future major upgrade can safely change the "show" class name without affecting the end-developper result (supposing the documentation clearly enforce to use Toast.isShown()
).