Skip to content

Commit 0782ff3

Browse files
committed
Adds failing test and example of selected tab functionality
1 parent 3a0377f commit 0782ff3

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

examples/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ <h2>Vertical (custom tablist)</h2>
8383
</div>
8484
</tab-container>
8585

86+
<h2>Set initially selected tab</h2>
87+
88+
<tab-container>
89+
<button type="button" id="tab-one" role="tab">Tab one</button>
90+
<button type="button" id="tab-two" role="tab" aria-selected="true">Tab two</button>
91+
<button type="button" id="tab-three" role="tab">Tab three</button>
92+
<div role="tabpanel" aria-labelledby="tab-one" hidden>
93+
Panel 1
94+
</div>
95+
<div role="tabpanel" aria-labelledby="tab-two">
96+
Panel 2
97+
</div>
98+
<div role="tabpanel" aria-labelledby="tab-three" hidden>
99+
Panel 3
100+
</div>
101+
</tab-container>
102+
86103
<h2>Panel with extra buttons</h2>
87104

88105
<tab-container>

test/test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,42 @@ describe('tab-container', function () {
4545
})
4646
})
4747

48+
describe('after tree insertion with aria-selected on second tab', function () {
49+
beforeEach(function () {
50+
document.body.innerHTML = `
51+
<tab-container>
52+
<button type="button" role="tab">Tab one</button>
53+
<button type="button" role="tab" aria-selected="true">Tab two</button>
54+
<button type="button" role="tab">Tab three</button>
55+
<div role="tabpanel" hidden>
56+
Panel 1
57+
</div>
58+
<div role="tabpanel">
59+
Panel 2
60+
</div>
61+
<div role="tabpanel" hidden data-tab-container-no-tabstop>
62+
Panel 3
63+
</div>
64+
</tab-container>
65+
`
66+
tabContainer = document.querySelector('tab-container')
67+
tabs = Array.from(document.querySelectorAll('button'))
68+
panels = Array.from(document.querySelectorAll('[role="tabpanel"]'))
69+
events = []
70+
tabContainer.addEventListener('tab-container-change', e => events.push(e))
71+
tabContainer.addEventListener('tab-container-changed', e => events.push(e))
72+
})
73+
74+
afterEach(function () {
75+
document.body.innerHTML = ''
76+
})
77+
78+
it('the second tab is still selected', function () {
79+
assert.deepStrictEqual(tabs.map(isSelected), [false, true, false], 'Second tab is selected')
80+
assert.deepStrictEqual(panels.map(isHidden), [true, false, true], 'Second panel is visible')
81+
})
82+
})
83+
4884
describe('after tree insertion', function () {
4985
beforeEach(function () {
5086
document.body.innerHTML = `

0 commit comments

Comments
 (0)