From 64b25fb9134f05c5751e525ce9252ff5ac6622f0 Mon Sep 17 00:00:00 2001 From: "Patrick H. Lauke" Date: Wed, 3 Mar 2021 21:14:10 +0000 Subject: [PATCH 1/5] show() should bail if the trigger has `disabled` attribute --- js/src/tab.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/src/tab.js b/js/src/tab.js index 95968f4f8ba8..82286888a312 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -67,7 +67,8 @@ class Tab extends BaseComponent { if ((this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && this._element.classList.contains(CLASS_NAME_ACTIVE)) || - this._element.classList.contains(CLASS_NAME_DISABLED)) { + this._element.classList.contains(CLASS_NAME_DISABLED) || + this._element.hasAttribute('disabled')) { return } From 12bad0f42f591ed808f539f4e04ad18001bc64c2 Mon Sep 17 00:00:00 2001 From: "Patrick H. Lauke" Date: Wed, 3 Mar 2021 21:17:34 +0000 Subject: [PATCH 2/5] Add relevant tests --- js/tests/unit/tab.spec.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/js/tests/unit/tab.spec.js b/js/tests/unit/tab.spec.js index 35d17e16b972..5c9be90ea3d9 100644 --- a/js/tests/unit/tab.spec.js +++ b/js/tests/unit/tab.spec.js @@ -198,11 +198,11 @@ describe('Tab', () => { }, 30) }) - it('should not fire shown when tab is disabled', done => { + it('should not fire shown when tab has disabled attribute', done => { fixtureEl.innerHTML = [ '', '
', '
', @@ -210,7 +210,33 @@ describe('Tab', () => { '
' ].join('') - const triggerDisabled = fixtureEl.querySelector('button.disabled') + const triggerDisabled = fixtureEl.querySelector('button[disabled]') + const tab = new Tab(triggerDisabled) + + triggerDisabled.addEventListener('shown.bs.tab', () => { + throw new Error('should not trigger shown event') + }) + + tab.show() + setTimeout(() => { + expect().nothing() + done() + }, 30) + }) + + it('should not fire shown when tab has disabled class', done => { + fixtureEl.innerHTML = [ + '', + '
', + '
', + '
', + '
' + ].join('') + + const triggerDisabled = fixtureEl.querySelector('a.disabled') const tab = new Tab(triggerDisabled) triggerDisabled.addEventListener('shown.bs.tab', () => { From 5cf54beaa7460b0edd53209734c9e811ee13c723 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Wed, 17 Mar 2021 10:26:58 +0200 Subject: [PATCH 3/5] use 'isDisabled' helper --- js/src/tab.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/js/src/tab.js b/js/src/tab.js index 82286888a312..ec3d790b09e1 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -10,6 +10,7 @@ import { emulateTransitionEnd, getElementFromSelector, getTransitionDurationFromElement, + isDisabled, reflow } from './util/index' import Data from './dom/data' @@ -36,7 +37,6 @@ const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}` const CLASS_NAME_DROPDOWN_MENU = 'dropdown-menu' const CLASS_NAME_ACTIVE = 'active' -const CLASS_NAME_DISABLED = 'disabled' const CLASS_NAME_FADE = 'fade' const CLASS_NAME_SHOW = 'show' @@ -67,8 +67,7 @@ class Tab extends BaseComponent { if ((this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && this._element.classList.contains(CLASS_NAME_ACTIVE)) || - this._element.classList.contains(CLASS_NAME_DISABLED) || - this._element.hasAttribute('disabled')) { + isDisabled(this._element)) { return } From f83dd22cd005ea1698d4682ea1b45f7ab8cf7b61 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 17 Mar 2021 10:47:03 +0200 Subject: [PATCH 4/5] Update tab.spec.js --- js/tests/unit/tab.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/tests/unit/tab.spec.js b/js/tests/unit/tab.spec.js index 5c9be90ea3d9..e76a0ff6a9f5 100644 --- a/js/tests/unit/tab.spec.js +++ b/js/tests/unit/tab.spec.js @@ -227,7 +227,7 @@ describe('Tab', () => { it('should not fire shown when tab has disabled class', done => { fixtureEl.innerHTML = [ '', '
', From dae5ebea61e6a45b39d7dd91cda539383b9f8614 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 17 Mar 2021 10:49:07 +0200 Subject: [PATCH 5/5] Update tab.spec.js --- js/tests/unit/tab.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/tests/unit/tab.spec.js b/js/tests/unit/tab.spec.js index e76a0ff6a9f5..231cf894c0f4 100644 --- a/js/tests/unit/tab.spec.js +++ b/js/tests/unit/tab.spec.js @@ -201,7 +201,7 @@ describe('Tab', () => { it('should not fire shown when tab has disabled attribute', done => { fixtureEl.innerHTML = [ '', '
',