diff options
author | Jacob Thornton <jacobthornton@gmail.com> | 2015-08-19 08:03:34 +0300 |
---|---|---|
committer | Jacob Thornton <jacobthornton@gmail.com> | 2015-08-19 08:03:34 +0300 |
commit | 03e732708c089b0446d946bd9bcbc40fb886f45e (patch) | |
tree | 86cf13534c09e3e2d0c7a296da29ff335da07045 | |
parent | 4e45e2363c452e57d187cfd3c64cb0503b881a40 (diff) |
rewrite tab with new active shit
-rw-r--r-- | js/dist/tab.js | 38 | ||||
-rw-r--r-- | js/dist/tab.js.map | 2 | ||||
-rw-r--r-- | js/src/tab.js | 38 | ||||
-rw-r--r-- | js/tests/unit/tab.js | 20 | ||||
-rw-r--r-- | js/tests/visual/tab.html | 36 |
5 files changed, 55 insertions, 79 deletions
diff --git a/js/dist/tab.js b/js/dist/tab.js index 33c2280583..8b175ea488 100644 --- a/js/dist/tab.js +++ b/js/dist/tab.js @@ -45,13 +45,14 @@ var Tab = (function ($) { var Selector = { A: 'a', LI: 'li', - LI_DROPDOWN: 'li.dropdown', + DROPDOWN: '.dropdown', UL: 'ul:not(.dropdown-menu)', - FADE_CHILD: '> .fade', + FADE_CHILD: '> .nav-item .fade, > .fade', ACTIVE: '.active', - ACTIVE_CHILD: '> .active', + ACTIVE_CHILD: '> .nav-item > .active, > .active', DATA_TOGGLE: '[data-toggle="tab"], [data-toggle="pill"]', - DROPDOWN_ACTIVE_CHILD: '> .dropdown-menu > .active' + DROPDOWN_TOGGLE: '.dropdown-toggle', + DROPDOWN_ACTIVE_CHILD: '> .dropdown-menu .active' }; /** @@ -83,7 +84,7 @@ var Tab = (function ($) { value: function show() { var _this = this; - if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).parent().hasClass(ClassName.ACTIVE)) { + if (this._element.parentNode && this._element.parentNode.nodeType === Node.ELEMENT_NODE && $(this._element).hasClass(ClassName.ACTIVE)) { return; } @@ -95,10 +96,6 @@ var Tab = (function ($) { if (ulElement) { previous = $.makeArray($(ulElement).find(Selector.ACTIVE)); previous = previous[previous.length - 1]; - - if (previous) { - previous = $(previous).find(Selector.A)[0]; - } } var hideEvent = $.Event(Event.HIDE, { @@ -123,7 +120,7 @@ var Tab = (function ($) { target = $(selector)[0]; } - this._activate($(this._element).closest(Selector.LI)[0], ulElement); + this._activate(this._element, ulElement); var complete = function complete() { var hiddenEvent = $.Event(Event.HIDDEN, { @@ -178,22 +175,16 @@ var Tab = (function ($) { $(active).removeClass(ClassName.ACTIVE); var dropdownChild = $(active).find(Selector.DROPDOWN_ACTIVE_CHILD)[0]; + if (dropdownChild) { $(dropdownChild).removeClass(ClassName.ACTIVE); } - var activeToggle = $(active).find(Selector.DATA_TOGGLE)[0]; - if (activeToggle) { - activeToggle.setAttribute('aria-expanded', false); - } + active.setAttribute('aria-expanded', false); } $(element).addClass(ClassName.ACTIVE); - - var elementToggle = $(element).find(Selector.DATA_TOGGLE)[0]; - if (elementToggle) { - elementToggle.setAttribute('aria-expanded', true); - } + element.setAttribute('aria-expanded', true); if (isTransitioning) { Util.reflow(element); @@ -204,15 +195,12 @@ var Tab = (function ($) { if (element.parentNode && $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) { - var dropdownElement = $(element).closest(Selector.LI_DROPDOWN)[0]; + var dropdownElement = $(element).closest(Selector.DROPDOWN)[0]; if (dropdownElement) { - $(dropdownElement).addClass(ClassName.ACTIVE); + $(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE); } - elementToggle = $(element).find(Selector.DATA_TOGGLE)[0]; - if (elementToggle) { - elementToggle.setAttribute('aria-expanded', true); - } + element.setAttribute('aria-expanded', true); } if (callback) { diff --git a/js/dist/tab.js.map b/js/dist/tab.js.map index 58eeccb93e..e76463c686 100644 --- a/js/dist/tab.js.map +++ b/js/dist/tab.js.map @@ -1 +1 @@ -{"version":3,"sources":["js/src/tab.js"],"names":[],"mappings":";;;;;;;;;;;;;AAUA,IAAM,GAAG,GAAG,CAAC,UAAC,CAAC,EAAK;;;;;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M,CAAC,CAAA","file":"js/src/tab.js","sourcesContent":["import Util from './util'\n\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.0.0): tab.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst Tab = (($) => {\n\n\n /**\n * ------------------------------------------------------------------------\n * Constants\n * ------------------------------------------------------------------------\n */\n\n const NAME = 'tab'\n const VERSION = '4.0.0'\n const DATA_KEY = 'bs.tab'\n const EVENT_KEY = `.${DATA_KEY}`\n const DATA_API_KEY = '.data-api'\n const JQUERY_NO_CONFLICT = $.fn[NAME]\n const TRANSITION_DURATION = 150\n\n const Event = {\n HIDE : `hide${EVENT_KEY}`,\n HIDDEN : `hidden${EVENT_KEY}`,\n SHOW : `show${EVENT_KEY}`,\n SHOWN : `shown${EVENT_KEY}`,\n CLICK_DATA_API : `click${EVENT_KEY}${DATA_API_KEY}`\n }\n\n const ClassName = {\n DROPDOWN_MENU : 'dropdown-menu',\n ACTIVE : 'active',\n FADE : 'fade',\n IN : 'in'\n }\n\n const Selector = {\n A : 'a',\n LI : 'li',\n LI_DROPDOWN : 'li.dropdown',\n UL : 'ul:not(.dropdown-menu)',\n FADE_CHILD : '> .fade',\n ACTIVE : '.active',\n ACTIVE_CHILD : '> .active',\n DATA_TOGGLE : '[data-toggle=\"tab\"], [data-toggle=\"pill\"]',\n DROPDOWN_ACTIVE_CHILD : '> .dropdown-menu > .active'\n }\n\n\n /**\n * ------------------------------------------------------------------------\n * Class Definition\n * ------------------------------------------------------------------------\n */\n\n class Tab {\n\n constructor(element) {\n this._element = element\n }\n\n\n // getters\n\n static get VERSION() {\n return VERSION\n }\n\n\n // public\n\n show() {\n if (this._element.parentNode &&\n (this._element.parentNode.nodeType === Node.ELEMENT_NODE) &&\n ($(this._element).parent().hasClass(ClassName.ACTIVE))) {\n return\n }\n\n let target\n let previous\n let ulElement = $(this._element).closest(Selector.UL)[0]\n let selector = Util.getSelectorFromElement(this._element)\n\n if (ulElement) {\n previous = $.makeArray($(ulElement).find(Selector.ACTIVE))\n previous = previous[previous.length - 1]\n\n if (previous) {\n previous = $(previous).find(Selector.A)[0]\n }\n }\n\n let hideEvent = $.Event(Event.HIDE, {\n relatedTarget: this._element\n })\n\n let showEvent = $.Event(Event.SHOW, {\n relatedTarget: previous\n })\n\n if (previous) {\n $(previous).trigger(hideEvent)\n }\n\n $(this._element).trigger(showEvent)\n\n if (showEvent.isDefaultPrevented() ||\n (hideEvent.isDefaultPrevented())) {\n return\n }\n\n if (selector) {\n target = $(selector)[0]\n }\n\n this._activate(\n $(this._element).closest(Selector.LI)[0],\n ulElement\n )\n\n let complete = () => {\n let hiddenEvent = $.Event(Event.HIDDEN, {\n relatedTarget: this._element\n })\n\n let shownEvent = $.Event(Event.SHOWN, {\n relatedTarget: previous\n })\n\n $(previous).trigger(hiddenEvent)\n $(this._element).trigger(shownEvent)\n }\n\n if (target) {\n this._activate(target, target.parentNode, complete)\n } else {\n complete()\n }\n }\n\n dispose() {\n $.removeClass(this._element, DATA_KEY)\n this._element = null\n }\n\n\n // private\n\n _activate(element, container, callback) {\n let active = $(container).find(Selector.ACTIVE_CHILD)[0]\n let isTransitioning = callback\n && Util.supportsTransitionEnd()\n && ((active && $(active).hasClass(ClassName.FADE))\n || Boolean($(container).find(Selector.FADE_CHILD)[0]))\n\n let complete = $.proxy(\n this._transitionComplete,\n this,\n element,\n active,\n isTransitioning,\n callback\n )\n\n if (active && isTransitioning) {\n $(active)\n .one(Util.TRANSITION_END, complete)\n .emulateTransitionEnd(TRANSITION_DURATION)\n\n } else {\n complete()\n }\n\n if (active) {\n $(active).removeClass(ClassName.IN)\n }\n }\n\n _transitionComplete(element, active, isTransitioning, callback) {\n if (active) {\n $(active).removeClass(ClassName.ACTIVE)\n\n let dropdownChild = $(active).find(\n Selector.DROPDOWN_ACTIVE_CHILD\n )[0]\n if (dropdownChild) {\n $(dropdownChild).removeClass(ClassName.ACTIVE)\n }\n\n let activeToggle = $(active).find(Selector.DATA_TOGGLE)[0]\n if (activeToggle) {\n activeToggle.setAttribute('aria-expanded', false)\n }\n }\n\n $(element).addClass(ClassName.ACTIVE)\n\n let elementToggle = $(element).find(Selector.DATA_TOGGLE)[0]\n if (elementToggle) {\n elementToggle.setAttribute('aria-expanded', true)\n }\n\n if (isTransitioning) {\n Util.reflow(element)\n $(element).addClass(ClassName.IN)\n } else {\n $(element).removeClass(ClassName.FADE)\n }\n\n if (element.parentNode &&\n ($(element.parentNode).hasClass(ClassName.DROPDOWN_MENU))) {\n\n let dropdownElement = $(element).closest(Selector.LI_DROPDOWN)[0]\n if (dropdownElement) {\n $(dropdownElement).addClass(ClassName.ACTIVE)\n }\n\n elementToggle = $(element).find(Selector.DATA_TOGGLE)[0]\n if (elementToggle) {\n elementToggle.setAttribute('aria-expanded', true)\n }\n }\n\n if (callback) {\n callback()\n }\n }\n\n\n // static\n\n static _jQueryInterface(config) {\n return this.each(function () {\n let $this = $(this)\n let data = $this.data(DATA_KEY)\n\n if (!data) {\n data = data = new Tab(this)\n $this.data(DATA_KEY, data)\n }\n\n if (typeof config === 'string') {\n data[config]()\n }\n })\n }\n\n }\n\n\n /**\n * ------------------------------------------------------------------------\n * Data Api implementation\n * ------------------------------------------------------------------------\n */\n\n $(document)\n .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {\n event.preventDefault()\n Tab._jQueryInterface.call($(this), 'show')\n })\n\n\n /**\n * ------------------------------------------------------------------------\n * jQuery\n * ------------------------------------------------------------------------\n */\n\n $.fn[NAME] = Tab._jQueryInterface\n $.fn[NAME].Constructor = Tab\n $.fn[NAME].noConflict = function () {\n $.fn[NAME] = JQUERY_NO_CONFLICT\n return Tab._jQueryInterface\n }\n\n return Tab\n\n})(jQuery)\n\nexport default Tab\n"]}
\ No newline at end of file +{"version":3,"sources":["js/src/tab.js"],"names":[],"mappings":";;;;;;;;;;;;;AAUA,IAAM,GAAG,GAAG,CAAC,UAAC,CAAC,EAAK;;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AA4LT,GAAC,CAAC,QAAQ,CAAC,CACR,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,WAAW,EAAE,UAAU,KAAK,EAAE;AACjE,SAAK,CAAC,cAAc,EAAE,CAAA;AACtB,OAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAA;GAC3C,CAAC,CAAA;;;;;;;;AASF,GAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAe,GAAG,CAAC,gBAAgB,CAAA;AAC7C,GAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,GAAG,GAAG,CAAA;AAC5B,GAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,GAAI,YAAY;AACnC,KAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAA;AAC/B,WAAO,GAAG,CAAC,gBAAgB,CAAA;GAC5B,CAAA;;AAED,SAAO,GAAG,CAAA;CAEX,CAAA,CAAE,MAAM,CAAC,CAAA","file":"js/src/tab.js","sourcesContent":["import Util from './util'\n\n\n/**\n * --------------------------------------------------------------------------\n * Bootstrap (v4.0.0): tab.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst Tab = (($) => {\n\n\n /**\n * ------------------------------------------------------------------------\n * Constants\n * ------------------------------------------------------------------------\n */\n\n const NAME = 'tab'\n const VERSION = '4.0.0'\n const DATA_KEY = 'bs.tab'\n const EVENT_KEY = `.${DATA_KEY}`\n const DATA_API_KEY = '.data-api'\n const JQUERY_NO_CONFLICT = $.fn[NAME]\n const TRANSITION_DURATION = 150\n\n const Event = {\n HIDE : `hide${EVENT_KEY}`,\n HIDDEN : `hidden${EVENT_KEY}`,\n SHOW : `show${EVENT_KEY}`,\n SHOWN : `shown${EVENT_KEY}`,\n CLICK_DATA_API : `click${EVENT_KEY}${DATA_API_KEY}`\n }\n\n const ClassName = {\n DROPDOWN_MENU : 'dropdown-menu',\n ACTIVE : 'active',\n FADE : 'fade',\n IN : 'in'\n }\n\n const Selector = {\n A : 'a',\n LI : 'li',\n DROPDOWN : '.dropdown',\n UL : 'ul:not(.dropdown-menu)',\n FADE_CHILD : '> .nav-item .fade, > .fade',\n ACTIVE : '.active',\n ACTIVE_CHILD : '> .nav-item > .active, > .active',\n DATA_TOGGLE : '[data-toggle=\"tab\"], [data-toggle=\"pill\"]',\n DROPDOWN_TOGGLE : '.dropdown-toggle',\n DROPDOWN_ACTIVE_CHILD : '> .dropdown-menu .active'\n }\n\n\n /**\n * ------------------------------------------------------------------------\n * Class Definition\n * ------------------------------------------------------------------------\n */\n\n class Tab {\n\n constructor(element) {\n this._element = element\n }\n\n\n // getters\n\n static get VERSION() {\n return VERSION\n }\n\n\n // public\n\n show() {\n if (this._element.parentNode &&\n (this._element.parentNode.nodeType === Node.ELEMENT_NODE) &&\n ($(this._element).hasClass(ClassName.ACTIVE))) {\n return\n }\n\n let target\n let previous\n let ulElement = $(this._element).closest(Selector.UL)[0]\n let selector = Util.getSelectorFromElement(this._element)\n\n if (ulElement) {\n previous = $.makeArray($(ulElement).find(Selector.ACTIVE))\n previous = previous[previous.length - 1]\n }\n\n let hideEvent = $.Event(Event.HIDE, {\n relatedTarget: this._element\n })\n\n let showEvent = $.Event(Event.SHOW, {\n relatedTarget: previous\n })\n\n if (previous) {\n $(previous).trigger(hideEvent)\n }\n\n $(this._element).trigger(showEvent)\n\n if (showEvent.isDefaultPrevented() ||\n (hideEvent.isDefaultPrevented())) {\n return\n }\n\n if (selector) {\n target = $(selector)[0]\n }\n\n this._activate(\n this._element,\n ulElement\n )\n\n let complete = () => {\n let hiddenEvent = $.Event(Event.HIDDEN, {\n relatedTarget: this._element\n })\n\n let shownEvent = $.Event(Event.SHOWN, {\n relatedTarget: previous\n })\n\n $(previous).trigger(hiddenEvent)\n $(this._element).trigger(shownEvent)\n }\n\n if (target) {\n this._activate(target, target.parentNode, complete)\n } else {\n complete()\n }\n }\n\n dispose() {\n $.removeClass(this._element, DATA_KEY)\n this._element = null\n }\n\n\n // private\n\n _activate(element, container, callback) {\n let active = $(container).find(Selector.ACTIVE_CHILD)[0]\n let isTransitioning = callback\n && Util.supportsTransitionEnd()\n && ((active && $(active).hasClass(ClassName.FADE))\n || Boolean($(container).find(Selector.FADE_CHILD)[0]))\n\n let complete = $.proxy(\n this._transitionComplete,\n this,\n element,\n active,\n isTransitioning,\n callback\n )\n\n if (active && isTransitioning) {\n $(active)\n .one(Util.TRANSITION_END, complete)\n .emulateTransitionEnd(TRANSITION_DURATION)\n\n } else {\n complete()\n }\n\n if (active) {\n $(active).removeClass(ClassName.IN)\n }\n }\n\n _transitionComplete(element, active, isTransitioning, callback) {\n if (active) {\n $(active).removeClass(ClassName.ACTIVE)\n\n let dropdownChild = $(active).find(\n Selector.DROPDOWN_ACTIVE_CHILD\n )[0]\n\n if (dropdownChild) {\n $(dropdownChild).removeClass(ClassName.ACTIVE)\n }\n\n active.setAttribute('aria-expanded', false)\n }\n\n $(element).addClass(ClassName.ACTIVE)\n element.setAttribute('aria-expanded', true)\n\n if (isTransitioning) {\n Util.reflow(element)\n $(element).addClass(ClassName.IN)\n } else {\n $(element).removeClass(ClassName.FADE)\n }\n\n if (element.parentNode &&\n ($(element.parentNode).hasClass(ClassName.DROPDOWN_MENU))) {\n\n let dropdownElement = $(element).closest(Selector.DROPDOWN)[0]\n if (dropdownElement) {\n $(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE)\n }\n\n element.setAttribute('aria-expanded', true)\n }\n\n if (callback) {\n callback()\n }\n }\n\n\n // static\n\n static _jQueryInterface(config) {\n return this.each(function () {\n let $this = $(this)\n let data = $this.data(DATA_KEY)\n\n if (!data) {\n data = data = new Tab(this)\n $this.data(DATA_KEY, data)\n }\n\n if (typeof config === 'string') {\n data[config]()\n }\n })\n }\n\n }\n\n\n /**\n * ------------------------------------------------------------------------\n * Data Api implementation\n * ------------------------------------------------------------------------\n */\n\n $(document)\n .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {\n event.preventDefault()\n Tab._jQueryInterface.call($(this), 'show')\n })\n\n\n /**\n * ------------------------------------------------------------------------\n * jQuery\n * ------------------------------------------------------------------------\n */\n\n $.fn[NAME] = Tab._jQueryInterface\n $.fn[NAME].Constructor = Tab\n $.fn[NAME].noConflict = function () {\n $.fn[NAME] = JQUERY_NO_CONFLICT\n return Tab._jQueryInterface\n }\n\n return Tab\n\n})(jQuery)\n\nexport default Tab\n"]}
\ No newline at end of file diff --git a/js/src/tab.js b/js/src/tab.js index 9d793417a4..4b311c24e3 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -43,13 +43,14 @@ const Tab = (($) => { const Selector = { A : 'a', LI : 'li', - LI_DROPDOWN : 'li.dropdown', + DROPDOWN : '.dropdown', UL : 'ul:not(.dropdown-menu)', - FADE_CHILD : '> .fade', + FADE_CHILD : '> .nav-item .fade, > .fade', ACTIVE : '.active', - ACTIVE_CHILD : '> .active', + ACTIVE_CHILD : '> .nav-item > .active, > .active', DATA_TOGGLE : '[data-toggle="tab"], [data-toggle="pill"]', - DROPDOWN_ACTIVE_CHILD : '> .dropdown-menu > .active' + DROPDOWN_TOGGLE : '.dropdown-toggle', + DROPDOWN_ACTIVE_CHILD : '> .dropdown-menu .active' } @@ -78,7 +79,7 @@ const Tab = (($) => { show() { if (this._element.parentNode && (this._element.parentNode.nodeType === Node.ELEMENT_NODE) && - ($(this._element).parent().hasClass(ClassName.ACTIVE))) { + ($(this._element).hasClass(ClassName.ACTIVE))) { return } @@ -90,10 +91,6 @@ const Tab = (($) => { if (ulElement) { previous = $.makeArray($(ulElement).find(Selector.ACTIVE)) previous = previous[previous.length - 1] - - if (previous) { - previous = $(previous).find(Selector.A)[0] - } } let hideEvent = $.Event(Event.HIDE, { @@ -120,7 +117,7 @@ const Tab = (($) => { } this._activate( - $(this._element).closest(Selector.LI)[0], + this._element, ulElement ) @@ -189,22 +186,16 @@ const Tab = (($) => { let dropdownChild = $(active).find( Selector.DROPDOWN_ACTIVE_CHILD )[0] + if (dropdownChild) { $(dropdownChild).removeClass(ClassName.ACTIVE) } - let activeToggle = $(active).find(Selector.DATA_TOGGLE)[0] - if (activeToggle) { - activeToggle.setAttribute('aria-expanded', false) - } + active.setAttribute('aria-expanded', false) } $(element).addClass(ClassName.ACTIVE) - - let elementToggle = $(element).find(Selector.DATA_TOGGLE)[0] - if (elementToggle) { - elementToggle.setAttribute('aria-expanded', true) - } + element.setAttribute('aria-expanded', true) if (isTransitioning) { Util.reflow(element) @@ -216,15 +207,12 @@ const Tab = (($) => { if (element.parentNode && ($(element.parentNode).hasClass(ClassName.DROPDOWN_MENU))) { - let dropdownElement = $(element).closest(Selector.LI_DROPDOWN)[0] + let dropdownElement = $(element).closest(Selector.DROPDOWN)[0] if (dropdownElement) { - $(dropdownElement).addClass(ClassName.ACTIVE) + $(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE) } - elementToggle = $(element).find(Selector.DATA_TOGGLE)[0] - if (elementToggle) { - elementToggle.setAttribute('aria-expanded', true) - } + element.setAttribute('aria-expanded', true) } if (callback) { diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js index 85d9f67a25..1eed75e90e 100644 --- a/js/tests/unit/tab.js +++ b/js/tests/unit/tab.js @@ -191,26 +191,26 @@ $(function () { QUnit.test('selected tab should have aria-expanded', function (assert) { assert.expect(8) var tabsHTML = '<ul class="nav nav-tabs">' - + '<li class="active"><a href="#home" toggle="tab" aria-expanded="true">Home</a></li>' - + '<li><a href="#profile" toggle="tab" aria-expanded="false">Profile</a></li>' + + '<li><a class="nav-item active" href="#home" toggle="tab" aria-expanded="true">Home</a></li>' + + '<li><a class="nav-item" href="#profile" toggle="tab" aria-expanded="false">Profile</a></li>' + '</ul>' var $tabs = $(tabsHTML).appendTo('#qunit-fixture') $tabs.find('li:first a').bootstrapTab('show') - assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true') - assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false') + assert.strictEqual($tabs.find('.active').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true') + assert.strictEqual($tabs.find('a:not(.active)').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false') $tabs.find('li:last a').trigger('click') - assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'after click, shown tab has aria-expanded = true') - assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'after click, hidden tab has aria-expanded = false') + assert.strictEqual($tabs.find('.active').attr('aria-expanded'), 'true', 'after click, shown tab has aria-expanded = true') + assert.strictEqual($tabs.find('a:not(.active)').attr('aria-expanded'), 'false', 'after click, hidden tab has aria-expanded = false') $tabs.find('li:first a').bootstrapTab('show') - assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true') - assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false') + assert.strictEqual($tabs.find('.active').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true') + assert.strictEqual($tabs.find('a:not(.active)').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false') $tabs.find('li:first a').trigger('click') - assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'after second show event, shown tab still has aria-expanded = true') - assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'after second show event, hidden tab has aria-expanded = false') + assert.strictEqual($tabs.find('.active').attr('aria-expanded'), 'true', 'after second show event, shown tab still has aria-expanded = true') + assert.strictEqual($tabs.find('a:not(.active)').attr('aria-expanded'), 'false', 'after second show event, hidden tab has aria-expanded = false') }) }) diff --git a/js/tests/visual/tab.html b/js/tests/visual/tab.html index ff6685fede..22a918ed75 100644 --- a/js/tests/visual/tab.html +++ b/js/tests/visual/tab.html @@ -35,14 +35,14 @@ <h4>Tabs without fade</h4> <ul id="myTab" class="nav nav-tabs"> - <li class="active nav-item"><a href="#home" class="nav-link" data-toggle="tab">Home</a></li> + <li class="nav-item"><a href="#home" class="nav-link active" data-toggle="tab">Home</a></li> <li class="nav-item"><a href="#profile" data-toggle="tab" class="nav-link">Profile</a></li> <li class="dropdown nav-item"> <a href="#" id="myTabDrop1" class="dropdown-toggle nav-link" data-toggle="dropdown">Dropdown <b class="caret"></b></a> - <ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1"> - <li><a href="#dropdown1" tabindex="-1" data-toggle="tab">@fat</a></li> - <li><a href="#dropdown2" tabindex="-1" data-toggle="tab">@mdo</a></li> - </ul> + <div class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1"> + <a class="dropdown-item" href="#dropdown1" tabindex="-1" data-toggle="tab">@fat</a> + <a class="dropdown-item" href="#dropdown2" tabindex="-1" data-toggle="tab">@mdo</a> + </div> </li> </ul> <div id="myTabContent" class="tab-content"> @@ -67,14 +67,14 @@ <h4>Tabs with fade</h4> <ul id="myTab1" class="nav nav-tabs"> - <li class="active nav-item"><a class="nav-link" href="#home1" data-toggle="tab">Home</a></li> + <li class="nav-item"><a class="nav-link active" href="#home1" data-toggle="tab">Home</a></li> <li class="nav-item"><a class="nav-link" href="#profile1" data-toggle="tab">Profile</a></li> <li class="dropdown nav-item"> <a href="#" id="myTabDrop2" class="dropdown-toggle nav-link" data-toggle="dropdown">Dropdown <b class="caret"></b></a> - <ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop2"> - <li><a href="#dropdown1-1" tabindex="-1" data-toggle="tab">@fat</a></li> - <li><a href="#dropdown1-2" tabindex="-1" data-toggle="tab">@mdo</a></li> - </ul> + <div class="dropdown-menu" role="menu" aria-labelledby="myTabDrop2"> + <a class="dropdown-item" href="#dropdown1-1" tabindex="-1" data-toggle="tab">@fat</a> + <a class="dropdown-item" href="#dropdown1-2" tabindex="-1" data-toggle="tab">@mdo</a> + </div> </li> </ul> <div id="myTabContent1" class="tab-content"> @@ -103,10 +103,10 @@ <li class="nav-item"><a class="nav-link" href="#profile2" data-toggle="tab">Profile</a></li> <li class="dropdown nav-item"> <a href="#" id="myTabDrop3" class="dropdown-toggle nav-link" data-toggle="dropdown">Dropdown <b class="caret"></b></a> - <ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop3"> - <li><a href="#dropdown2-1" tabindex="-1" data-toggle="tab">@fat</a></li> - <li><a href="#dropdown2-2" tabindex="-1" data-toggle="tab">@mdo</a></li> - </ul> + <div class="dropdown-menu" role="menu" aria-labelledby="myTabDrop3"> + <a class="dropdown-item" href="#dropdown2-1" tabindex="-1" data-toggle="tab">@fat</a> + <a class="dropdown-item" href="#dropdown2-2" tabindex="-1" data-toggle="tab">@mdo</a> + </div> </li> </ul> <div id="myTabContent2" class="tab-content"> @@ -135,10 +135,10 @@ <li class="nav-item"><a class="nav-link" href="#profile3" data-toggle="tab">Profile</a></li> <li class="dropdown nav-item"> <a href="#" id="myTabDrop4" class="dropdown-toggle nav-link" data-toggle="dropdown">Dropdown <b class="caret"></b></a> - <ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop4"> - <li><a href="#dropdown3-1" tabindex="-1" data-toggle="tab">@fat</a></li> - <li><a href="#dropdown3-2" tabindex="-1" data-toggle="tab">@mdo</a></li> - </ul> + <div class="dropdown-menu" role="menu" aria-labelledby="myTabDrop4"> + <a class="dropdown-item" href="#dropdown3-1" tabindex="-1" data-toggle="tab">@fat</a> + <a class="dropdown-item" href="#dropdown3-2" tabindex="-1" data-toggle="tab">@mdo</a> + </div> </li> </ul> <div id="myTabContent3" class="tab-content"> |