Skip to content

Commit be7ca0f

Browse files
authored
Merge pull request #1793 from Marghen/fix-cv-tabs-accessibility-problems
feat: fix CvTabs accessibility warnings and errors clicking overflow …
2 parents 22d1b77 + 752832d commit be7ca0f

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/components/CvTabs/CvTabs.vue

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,24 @@
1111
},
1212
]"
1313
role="navigation"
14-
v-bind="$attrs"
14+
:aria-label="attrs['aria-label'] || 'Tabs'"
15+
v-bind="attrsWithoutAriaLabel"
1516
@keydown.right.prevent.stop="onRight"
1617
@keydown.left.prevent.stop="onLeft"
1718
>
1819
<button
1920
ref="elLeftOverflow"
20-
aria-hidden="true"
21-
aria-label="scroll left"
21+
:aria-label="
22+
leftOverflowNavButtonHidden ? undefined : 'Scroll tabs left'
23+
"
2224
:class="[
2325
{
2426
[`${carbonPrefix}--tab--overflow-nav-button`]: horizontalOverflow,
2527
[`${carbonPrefix}--tab--overflow-nav-button--hidden`]:
2628
leftOverflowNavButtonHidden,
2729
},
2830
]"
29-
tabIndex="-1"
31+
:tabIndex="leftOverflowNavButtonHidden ? -1 : 0"
3032
type="button"
3133
@click.stop.prevent="e => onOverflowClick(e, { direction: -1 })"
3234
@mousedown.stop.prevent="e => onOverflowMouseDown(e, { direction: -1 })"
@@ -89,16 +91,17 @@
8991
/>
9092
<button
9193
ref="elRightOverflow"
92-
aria-hidden="true"
93-
aria-label="scroll right"
94+
:aria-label="
95+
rightOverflowNavButtonHidden ? undefined : 'Scroll tabs right'
96+
"
9497
:class="[
9598
{
9699
[`${carbonPrefix}--tab--overflow-nav-button`]: horizontalOverflow,
97100
[`${carbonPrefix}--tab--overflow-nav-button--hidden`]:
98101
rightOverflowNavButtonHidden,
99102
},
100103
]"
101-
tabIndex="-1"
104+
:tabIndex="rightOverflowNavButtonHidden ? -1 : 0"
102105
type="button"
103106
@click="e => onOverflowClick(e, { direction: 1 })"
104107
@mousedown="e => onOverflowMouseDown(e, { direction: 1 })"
@@ -117,15 +120,21 @@
117120
import { carbonPrefix } from '../../global/settings';
118121
import { ChevronLeft16, ChevronRight16 } from '@carbon/icons-vue';
119122
import {
123+
computed,
120124
nextTick,
121125
onBeforeUnmount,
122126
onMounted,
123127
onUpdated,
124128
provide,
125129
ref,
130+
useAttrs,
126131
watch,
127132
} from 'vue';
128133
134+
defineOptions({
135+
inheritAttrs: false,
136+
});
137+
129138
const OVERFLOW_BUTTON_OFFSET = 40;
130139
131140
const props = defineProps({
@@ -152,6 +161,12 @@ const props = defineProps({
152161
});
153162
const emit = defineEmits(['tab-selected', 'tab-selected-id']);
154163
164+
const attrs = useAttrs();
165+
const attrsWithoutAriaLabel = computed(() => {
166+
const { 'aria-label': _, ...rest } = attrs;
167+
return rest;
168+
});
169+
155170
const selectedId = ref('');
156171
provide('tab-selected', selectedId);
157172
/**

src/components/CvTabs/__tests__/__snapshots__/CvTabs.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`CvTabs CvTabs - test slotted tab buttons to match snapshot 1`] = `
4-
<div class="cv-tabs ABC-class-123" style="width: 100%;" aria-label="ABC-aria-label-123">
5-
<div data-tabs="" class="cv-tab bx--tabs--scrollable ABC-class-123" role="navigation" aria-label="ABC-aria-label-123"><button aria-hidden="true" aria-label="scroll left" class="bx--tab--overflow-nav-button--hidden" tabindex="-1" type="button"><svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
4+
<div class="cv-tabs" style="width: 100%;">
5+
<div data-tabs="" class="cv-tab bx--tabs--scrollable ABC-class-123" role="navigation" aria-label="ABC-aria-label-123"><button class="bx--tab--overflow-nav-button--hidden" tabindex="-1" type="button"><svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
66
<path d="M5 8L10 3 10.7 3.7 6.4 8 10.7 12.3 10 13z"></path>
77
</svg></button>
88
<!--v-if-->
@@ -11,7 +11,7 @@ exports[`CvTabs CvTabs - test slotted tab buttons to match snapshot 1`] = `
1111
<li class="cv-tabs-button bx--tabs--scrollable__nav-item" role="presentation"><button id="tab-2-link" class="bx--tabs--scrollable__nav-link" role="tab" aria-controls="tab-2" aria-selected="false" tabindex="-1" type="button">Origin<strong style="color: orange;">(!)</strong></button></li>
1212
<li class="cv-tabs-button bx--tabs--scrollable__nav-item" role="presentation"><button id="tab-3-link" class="bx--tabs--scrollable__nav-link" role="tab" aria-controls="tab-3" aria-selected="false" tabindex="-1" type="button">Tab 3 label</button></li>
1313
</ul>
14-
<!--v-if--><button aria-hidden="true" aria-label="scroll right" class="bx--tab--overflow-nav-button--hidden" tabindex="-1" type="button"><svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
14+
<!--v-if--><button class="bx--tab--overflow-nav-button--hidden" tabindex="-1" type="button"><svg focusable="false" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
1515
<path d="M11 8L6 13 5.3 12.3 9.6 8 5.3 3.7 6 3z"></path>
1616
</svg></button>
1717
</div>

0 commit comments

Comments
 (0)