From a15110a2bbd9944d567ce3f96b1e324f2b89d0db Mon Sep 17 00:00:00 2001 From: Thomas Brouard Date: Thu, 12 Mar 2020 21:56:23 +0100 Subject: [PATCH] Add tab.hasClass() method --- README.md | 4 ++++ index.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 375e181..69d12b4 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,10 @@ Toggle the "visible" class on the tab. `tab.hide()` is an alias to `tab.show(fal Toggle the "flash" class on the tab. `tab.unflash()` is an alias to `tab.flash(false)`. +#### `tab.hasClass(classname)` + +Return `true` if the tab element has the specified classname. Useful for checking if a tab is "active", "visible" of "flash". + #### `tab.close(force)` Close the tab (and activate another tab if relevant). When `force` is set to `true` the tab will be closed even if it is not `closable`. diff --git a/index.js b/index.js index 261f73b..8b79863 100644 --- a/index.js +++ b/index.js @@ -341,6 +341,10 @@ class Tab extends EventEmitter { return this.flash(false); } + hasClass (classname) { + return this.tab.classList.contains(classname); + } + close (force) { const abortController = new AbortController(); const abort = () => abortController.abort();