Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/components/CvTabs/CvTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@
},
]"
role="navigation"
v-bind="$attrs"
:aria-label="attrs['aria-label'] || 'Tabs'"
v-bind="attrsWithoutAriaLabel"
@keydown.right.prevent.stop="onRight"
@keydown.left.prevent.stop="onLeft"
>
<button
ref="elLeftOverflow"
aria-hidden="true"
aria-label="scroll left"
:aria-label="
leftOverflowNavButtonHidden ? undefined : 'Scroll tabs left'
"
:class="[
{
[`${carbonPrefix}--tab--overflow-nav-button`]: horizontalOverflow,
[`${carbonPrefix}--tab--overflow-nav-button--hidden`]:
leftOverflowNavButtonHidden,
},
]"
tabIndex="-1"
:tabIndex="leftOverflowNavButtonHidden ? -1 : 0"
type="button"
@click.stop.prevent="e => onOverflowClick(e, { direction: -1 })"
@mousedown.stop.prevent="e => onOverflowMouseDown(e, { direction: -1 })"
Expand Down Expand Up @@ -89,16 +91,17 @@
/>
<button
ref="elRightOverflow"
aria-hidden="true"
aria-label="scroll right"
:aria-label="
rightOverflowNavButtonHidden ? undefined : 'Scroll tabs right'
"
:class="[
{
[`${carbonPrefix}--tab--overflow-nav-button`]: horizontalOverflow,
[`${carbonPrefix}--tab--overflow-nav-button--hidden`]:
rightOverflowNavButtonHidden,
},
]"
tabIndex="-1"
:tabIndex="rightOverflowNavButtonHidden ? -1 : 0"
type="button"
@click="e => onOverflowClick(e, { direction: 1 })"
@mousedown="e => onOverflowMouseDown(e, { direction: 1 })"
Expand All @@ -117,15 +120,21 @@
import { carbonPrefix } from '../../global/settings';
import { ChevronLeft16, ChevronRight16 } from '@carbon/icons-vue';
import {
computed,
nextTick,
onBeforeUnmount,
onMounted,
onUpdated,
provide,
ref,
useAttrs,
watch,
} from 'vue';

defineOptions({
inheritAttrs: false,
});

const OVERFLOW_BUTTON_OFFSET = 40;

const props = defineProps({
Expand All @@ -152,6 +161,12 @@ const props = defineProps({
});
const emit = defineEmits(['tab-selected', 'tab-selected-id']);

const attrs = useAttrs();
const attrsWithoutAriaLabel = computed(() => {
const { 'aria-label': _, ...rest } = attrs;
return rest;
});

const selectedId = ref('');
provide('tab-selected', selectedId);
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CvTabs CvTabs - test slotted tab buttons to match snapshot 1`] = `
<div class="cv-tabs ABC-class-123" style="width: 100%;" aria-label="ABC-aria-label-123">
<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">
<div class="cv-tabs" style="width: 100%;">
<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">
<path d="M5 8L10 3 10.7 3.7 6.4 8 10.7 12.3 10 13z"></path>
</svg></button>
<!--v-if-->
Expand All @@ -11,7 +11,7 @@ exports[`CvTabs CvTabs - test slotted tab buttons to match snapshot 1`] = `
<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>
<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>
</ul>
<!--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">
<!--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">
<path d="M11 8L6 13 5.3 12.3 9.6 8 5.3 3.7 6 3z"></path>
</svg></button>
</div>
Expand Down