From 7d57d9a68bbc2bc703fbf2c66fd2ad2546d67557 Mon Sep 17 00:00:00 2001 From: "Patrick H. Lauke" Date: Tue, 24 May 2022 19:16:58 +0100 Subject: [PATCH] Dynamic tabs: use buttons rather than links (backport to v4) (#33163) * Manually backport 32630 Dynamic tabs: use buttons rather than links * Tweak unit test * Tweak unit tests * More tweakage * show() should also bail if `disabled` attribute is set * Tweak tests * Simplify test for relatedTarget * Temporarily remove problematic test (as i can't get local tests to run just noww) * Revert previous * test: fix broken test cases for tab.js * test: fix role=tablist invalid on nav element * test: prefer
over
* Manually backport 32630 Dynamic tabs: use buttons rather than links * test: fix broken test cases for tab.js * Fixes * Remove and ignore lock file Co-authored-by: alpadev Co-authored-by: Mark Otto Co-authored-by: Mark Otto --- .gitignore | 3 +- js/src/tab.js | 3 +- js/tests/unit/tab.js | 211 +++++++++++------------ js/tests/visual/tab.html | 57 +++--- scss/_nav.scss | 5 + site/content/docs/4.6/components/navs.md | 86 ++++----- 6 files changed, 181 insertions(+), 184 deletions(-) diff --git a/.gitignore b/.gitignore index 6b724135872c..2215d636addf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ # Ignore docs files /_site/ -# Hugo folders +# Hugo files /resources/ +/.hugo_build.lock # Numerous always-ignore extensions *.diff diff --git a/js/src/tab.js b/js/src/tab.js index 85f2f2ebc19c..9c2e22d088d3 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -58,7 +58,8 @@ class Tab { if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).hasClass(CLASS_NAME_ACTIVE) || - $(this._element).hasClass(CLASS_NAME_DISABLED)) { + $(this._element).hasClass(CLASS_NAME_DISABLED) || + this._element.hasAttribute('disabled')) { return } diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js index 9ede231c5b78..8f80a00c84ba 100644 --- a/js/tests/unit/tab.js +++ b/js/tests/unit/tab.js @@ -44,14 +44,30 @@ $(function () { assert.strictEqual($tab[0], $el[0], 'collection contains element') }) - QUnit.test('should activate element by tab id', function (assert) { + QUnit.test('should activate element by tab id (using buttons, the preferred semantic way)', function (assert) { assert.expect(2) - var tabsHTML = '