diff --git a/js/src/tab.js b/js/src/tab.js index 95968f4f8b..ec3d790b09 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,7 +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)) { + isDisabled(this._element)) { return } diff --git a/js/tests/unit/tab.spec.js b/js/tests/unit/tab.spec.js index 35d17e16b9..231cf894c0 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', () => {