Skip to content

Commit fc41b66

Browse files
authored
Merge pull request #24 from github/remove-tabindex-from-panels
Don't set `tabindex` on panels
2 parents cd0f694 + b514492 commit fc41b66

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ function selectTab(tabContainer: TabContainerElement, index: number) {
7878
}
7979
for (const panel of panels) {
8080
panel.hidden = true
81-
panel.setAttribute('tabindex', '0')
81+
if (!panel.hasAttribute('tabindex') && !panel.hasAttribute('data-tab-container-no-tabstop')) {
82+
panel.setAttribute('tabindex', '0')
83+
}
8284
}
8385

8486
selectedTab.setAttribute('aria-selected', 'true')

test/test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('tab-container', function() {
2626
<div role="tabpanel" hidden>
2727
Panel 2
2828
</div>
29-
<div role="tabpanel" hidden>
29+
<div role="tabpanel" hidden data-tab-container-no-tabstop>
3030
Panel 3
3131
</div>
3232
</tab-container>
@@ -94,6 +94,17 @@ describe('tab-container', function() {
9494
assert.equal(counter, 1)
9595
})
9696

97+
it("panels that don't have a `data-tab-container-no-tabstop` attribute have tabindex with value '0'", function() {
98+
const tabs = document.querySelectorAll('button')
99+
const panels = document.querySelectorAll('[role="tabpanel"]')
100+
101+
tabs[1].click()
102+
103+
assert.equal(panels[0].getAttribute('tabindex'), '0')
104+
assert.equal(panels[1].getAttribute('tabindex'), '0')
105+
assert(!panels[2].hasAttribute('tabindex'))
106+
})
107+
97108
it('the aria-selected attribute is set to "false" for all tabs that don\'t have a aria-selected attribute', function() {
98109
for (const tab of document.querySelectorAll('[role="tab"]:not([aria-selected="true"])')) {
99110
assert.equal(tab.getAttribute('aria-selected'), 'false')

0 commit comments

Comments
 (0)