Skip to content

Commit

Permalink
fix(LinkCustom): improve prop binding and prevent error with externals
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Jul 19, 2023
1 parent 0f06b7c commit 914d156
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions src/runtime/components/elements/LinkCustom.vue
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
<template>
<button v-if="!$attrs.to" v-bind="$attrs" :class="inactiveClass">
<button v-if="!to" v-bind="$attrs" :class="inactiveClass">
<slot />
</button>
<NuxtLink
v-else
v-slot="{ href, navigate, exact, isActive, isExactActive }"
:to="$attrs.to"
v-slot="{ href, target, rel, navigate, exact, isActive, isExactActive, isExternal }"
v-bind="$props"
custom
>
<a
v-bind="$attrs"
:href="href"
:rel="rel"
:target="target"
:class="resolveLinkClass({ isActive, isExactActive })"
@click="navigate"
@click="(e) => !isExternal && navigate(e)"
>
<slot v-bind="{ isActive: exact ? isExactActive : isActive }" />
</a>
</NuxtLink>
</template>

<script setup lang="ts">
const props = defineProps({
activeClass: {
type: String,
default: ''
<script lang="ts">
import { defineComponent } from 'vue'
import { NuxtLink } from '#components'
export default defineComponent({
inheritAttrs: false,
props: {
...NuxtLink.props,
inactiveClass: {
type: String,
default: undefined
}
},
inactiveClass: {
type: String,
default: ''
}
})
setup (props) {
function resolveLinkClass ({ isActive, isExactActive }: { isActive: boolean, isExactActive: boolean }) {
if (isActive || isExactActive) {
return props.activeClass
}
function resolveLinkClass ({ isActive, isExactActive }: { isActive: boolean, isExactActive: boolean }) {
if (isActive || isExactActive) {
return props.activeClass
}
return props.inactiveClass
}
return props.inactiveClass
}
return {
resolveLinkClass
}
}
})
</script>

1 comment on commit 914d156

@vercel
Copy link

@vercel vercel bot commented on 914d156 Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-nuxtlabs.vercel.app
ui-git-dev-nuxtlabs.vercel.app
ui.nuxtlabs.com

Please sign in to comment.