Skip to content

Commit 55ed1db

Browse files
committed
fix: tab animation when link
1 parent bf1bcb5 commit 55ed1db

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

packages/ui/src/components/va-tabs/VaTabs.demo.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@
348348
<template #tabs>
349349
<va-tab
350350
name="Link 1"
351-
to="/demo/components/va-breadcrumbs/VaBreadcrumbs.demo.vue"
351+
to="/1"
352352
>
353353
Link 1
354354
</va-tab>
355355
<va-tab
356356
name="Link 2"
357-
to="/demo/components/va-tabs/VaTabs.demo.vue"
357+
to="/2"
358358
>
359359
Active link
360360
</va-tab>

packages/ui/src/components/va-tabs/components/VaTab/VaTab.vue

+14-18
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,19 @@
66
role="tab"
77
:aria-selected="isActive"
88
:aria-disabled="$props.disabled || parentDisabled"
9-
:href="hrefComputed"
10-
:target="target"
11-
:to="to"
12-
:replace="replace"
13-
:exact="exact"
14-
:active-class="activeClass"
15-
:exact-active-class="exactActiveClass"
169
:class="classComputed"
1710
:style="computedStyle"
1811
@mouseenter="updateHoverState(true)"
1912
@mouseleave="updateHoverState(false)"
13+
@focus="onFocus"
14+
@click="onTabClick"
15+
@keydown.enter="onTabKeydown"
16+
:tabindex="tabIndexComputed"
17+
v-on="keyboardFocusListeners"
18+
v-bind="linkAttributesComputed"
2019
>
2120
<div
2221
class="va-tab__content"
23-
:tabindex="tabIndexComputed"
24-
@focus="onFocus"
25-
@click="onTabClick"
26-
@keydown.enter="onTabKeydown"
27-
v-on="keyboardFocusListeners"
2822
>
2923
<slot>
3024
<va-icon
@@ -43,7 +37,7 @@
4337
</template>
4438

4539
<script lang="ts" setup>
46-
import { computed, inject, onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'
40+
import { computed, inject, nextTick, onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'
4741
4842
import {
4943
useComponentPresetProp,
@@ -85,7 +79,7 @@ const leftSidePosition = ref(0)
8579
8680
const { keyboardFocusListeners, hasKeyboardFocus } = useKeyboardOnlyFocus()
8781
88-
const { tagComputed, hrefComputed, isActiveRouterLink } = useRouterLink(props)
82+
const { tagComputed, isActiveRouterLink, linkAttributesComputed } = useRouterLink(props)
8983
const classComputed = computed(() => ({ 'va-tab--disabled': props.disabled }))
9084
const {
9185
parentDisabled,
@@ -122,12 +116,14 @@ const updateSidePositions = () => {
122116
leftSidePosition.value = componentOffsetLeft
123117
}
124118
125-
const onTabClick = () => {
119+
const onTabClick = async () => {
120+
await nextTick()
126121
selectTab(tabComponent)
127122
emit('click')
128123
}
129124
130-
const onTabKeydown = () => {
125+
const onTabKeydown = async () => {
126+
await nextTick()
131127
selectTab(tabComponent)
132128
emit('keydown-enter')
133129
}
@@ -180,6 +176,8 @@ onBeforeUnmount(() => {
180176
vertical-align: var(--va-tab-vertical-align);
181177
color: var(--va-tab-color);
182178
179+
@include keyboard-focus-outline($radius: 2px, $offset: -2px);
180+
183181
&__content {
184182
align-items: var(--va-tab-content-align-items);
185183
color: var(--va-tab-content-color);
@@ -194,8 +192,6 @@ onBeforeUnmount(() => {
194192
white-space: var(--va-tab-content-white-space);
195193
padding: var(--va-tab-content-padding);
196194
cursor: var(--va-tab-content-cursor);
197-
198-
@include keyboard-focus-outline($radius: 2px, $offset: -2px);
199195
}
200196
201197
&__icon {

packages/ui/src/composables/useRouterLink.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export const useRouterLink = (props: ExtractPropTypes<typeof useRouterLinkProps>
3333

3434
if (globalConfig.routerComponent && props.to) { return globalConfig.routerComponent }
3535

36-
if (props.to) { return 'router-link' }
36+
if (props.to && vueRouter.value !== undefined) { return 'router-link' }
37+
if (props.to && vueRouter.value === undefined) { return 'a' }
3738

3839
return props.tag || 'div'
3940
})
@@ -73,10 +74,15 @@ export const useRouterLink = (props: ExtractPropTypes<typeof useRouterLinkProps>
7374
})
7475

7576
const hrefComputed = computed(() => {
77+
if (props.href) { return props.href }
78+
79+
if (vueRoute.value === undefined && props.to) {
80+
return props.to
81+
}
82+
7683
// to resolve href on server for SEO optimization
7784
// https://github.com/nuxt/nuxt.js/issues/8204
78-
// @ts-ignore
79-
return props.href || (props.to ? vueRouter.value?.resolve(props.to, vueRoute.value).href : undefined)
85+
return props.to ? vueRouter.value?.resolve(props.to, vueRoute.value).href : undefined
8086
})
8187

8288
return {

0 commit comments

Comments
 (0)