Skip to content

Commit 0f711a8

Browse files
committed
Better aria accessibility support
1 parent df24ea2 commit 0f711a8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/components/VTab.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export default {
3030
},
3131
hash () {
3232
return `#${this.id}`
33+
},
34+
tabId () {
35+
return this.id ? this.id : this.title
3336
}
3437
},
3538
data () {
@@ -50,6 +53,8 @@ export default {
5053
render () {
5154
return (
5255
<section class="tab-container"
56+
id={`p-${this.tabId}`}
57+
aria-labelledby={`t-${this.tabId}`}
5358
role="tabpanel" v-show={this.active}>
5459
{this.$slots.default}
5560
</section>)

src/components/VueTabs.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,16 @@ export default {
142142
renderTabs () {
143143
return this.tabs.map((tab, index) => {
144144
if (!tab) return
145-
let {route, id, title, icon} = tab
145+
let {route, id, title, icon, tabId} = tab
146146
let active = this.activeTabIndex === index
147147
return (
148148
<li name="tab" onClick={() => !tab.disabled && this.navigateToTab(index, route)}
149149
class={['tab', {active: active}, {disabled: tab.disabled}]}
150150
key={title}
151-
role="presentation">
151+
id={`t-${tabId}`}
152+
aria-selected={active}
153+
aria-controls={`p-${tabId}`}
154+
role="tab">
152155
{this.textPosition === 'top' &&
153156
this.renderTabTitle(index, this.textPosition)
154157
}
@@ -159,8 +162,6 @@ export default {
159162
}}
160163
style={active ? this.activeTabStyle : this.tabStyles(tab)}
161164
class={[{'active_tab': active}, 'tabs__link']}
162-
aria-selected={active}
163-
aria-controls={`#${id}`}
164165
role="tab">
165166
{this.textPosition !== 'center' && !tab.$slots.title && this.renderIcon(index)}
166167
{this.textPosition === 'center' &&

0 commit comments

Comments
 (0)