From 96be06e32bf68de22d8d14362909dd688070ca40 Mon Sep 17 00:00:00 2001 From: "Patrick H. Lauke" Date: Tue, 9 Feb 2021 05:23:45 +0000 Subject: [PATCH] Dynamic tabs: use buttons rather than links (#32630) * Dynamic tabs: use buttons rather than links - change docs - add mention that tabs should be ', + '
  • ', + '', + '' + ].join('') + + const profileTriggerEl = fixtureEl.querySelector('#triggerProfile') + const tab = new Tab(profileTriggerEl) + + profileTriggerEl.addEventListener('shown.bs.tab', () => { + expect(fixtureEl.querySelector('#profile').classList.contains('active')).toEqual(true) + expect(profileTriggerEl.getAttribute('aria-selected')).toEqual('true') + done() + }) + + tab.show() + }) + + it('should activate element by tab id (using links for tabs - not ideal, but still supported)', done => { + fixtureEl.innerHTML = [ + '', '' ].join('') @@ -48,12 +72,12 @@ describe('Tab', () => { it('should activate element by tab id in ordered list', done => { fixtureEl.innerHTML = [ '', '
      ', - '
    1. ', - '
    2. ', + '
    3. ', + '
    4. ', '
    ' ].join('') @@ -71,10 +95,10 @@ describe('Tab', () => { it('should activate element by tab id in nav list', done => { fixtureEl.innerHTML = [ '', - '' + '
    ' ].join('') const profileTriggerEl = fixtureEl.querySelector('#triggerProfile') @@ -90,11 +114,11 @@ describe('Tab', () => { it('should activate element by tab id in list group', done => { fixtureEl.innerHTML = [ - '
    ', - ' Home', - ' Profile', + '
    ', + ' ', + ' ', '
    ', - '' + '
    ' ].join('') const profileTriggerEl = fixtureEl.querySelector('#triggerProfile') @@ -135,8 +159,8 @@ describe('Tab', () => { it('should not fire shown when tab is already active', done => { fixtureEl.innerHTML = [ '', '
    ', '
    ', @@ -144,7 +168,7 @@ describe('Tab', () => { '
    ' ].join('') - const triggerActive = fixtureEl.querySelector('a.active') + const triggerActive = fixtureEl.querySelector('button.active') const tab = new Tab(triggerActive) triggerActive.addEventListener('shown.bs.tab', () => { @@ -161,8 +185,8 @@ describe('Tab', () => { it('should not fire shown when tab is disabled', done => { fixtureEl.innerHTML = [ '', '
    ', '
    ', @@ -170,7 +194,7 @@ describe('Tab', () => { '
    ' ].join('') - const triggerDisabled = fixtureEl.querySelector('a.disabled') + const triggerDisabled = fixtureEl.querySelector('button.disabled') const tab = new Tab(triggerDisabled) triggerDisabled.addEventListener('shown.bs.tab', () => { @@ -187,8 +211,8 @@ describe('Tab', () => { it('show and shown events should reference correct relatedTarget', done => { fixtureEl.innerHTML = [ '', '
    ', '
    ', @@ -200,13 +224,13 @@ describe('Tab', () => { const secondTab = new Tab(secondTabTrigger) secondTabTrigger.addEventListener('show.bs.tab', ev => { - expect(ev.relatedTarget.hash).toEqual('#home') + expect(ev.relatedTarget.getAttribute('data-bs-target')).toEqual('#home') }) secondTabTrigger.addEventListener('shown.bs.tab', ev => { - expect(ev.relatedTarget.hash).toEqual('#home') + expect(ev.relatedTarget.getAttribute('data-bs-target')).toEqual('#home') expect(secondTabTrigger.getAttribute('aria-selected')).toEqual('true') - expect(fixtureEl.querySelector('a:not(.active)').getAttribute('aria-selected')).toEqual('false') + expect(fixtureEl.querySelector('button:not(.active)').getAttribute('aria-selected')).toEqual('false') done() }) @@ -215,13 +239,13 @@ describe('Tab', () => { it('should fire hide and hidden events', done => { fixtureEl.innerHTML = [ - '