-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(LinkCustom): improve prop binding and prevent error with externals
- Loading branch information
1 parent
0f06b7c
commit 914d156
Showing
1 changed file
with
30 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
914d156
There was a problem hiding this comment.
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