diff options
Diffstat (limited to 'packages/frontend/src/components/global/MkA.vue')
| -rw-r--r-- | packages/frontend/src/components/global/MkA.vue | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/packages/frontend/src/components/global/MkA.vue b/packages/frontend/src/components/global/MkA.vue index 61d7ac17d9..d1e9113c48 100644 --- a/packages/frontend/src/components/global/MkA.vue +++ b/packages/frontend/src/components/global/MkA.vue @@ -4,13 +4,17 @@ SPDX-License-Identifier: AGPL-3.0-only --> <template> -<a :href="to" :class="active ? activeClass : null" @click.prevent="nav" @contextmenu.prevent.stop="onContextmenu"> +<a ref="el" :href="to" :class="active ? activeClass : null" @click.prevent="nav" @contextmenu.prevent.stop="onContextmenu"> <slot></slot> </a> </template> +<script lang="ts"> +export type MkABehavior = 'window' | 'browser' | null; +</script> + <script lang="ts" setup> -import { computed } from 'vue'; +import { computed, inject, shallowRef } from 'vue'; import * as os from '@/os.js'; import copyToClipboard from '@/scripts/copy-to-clipboard.js'; import { url } from '@/config.js'; @@ -20,12 +24,18 @@ import { useRouter } from '@/router/supplier.js'; const props = withDefaults(defineProps<{ to: string; activeClass?: null | string; - behavior?: null | 'window' | 'browser'; + behavior?: MkABehavior; }>(), { activeClass: null, behavior: null, }); +const behavior = props.behavior ?? inject<MkABehavior>('linkNavigationBehavior', null); + +const el = shallowRef<HTMLElement>(); + +defineExpose({ $el: el }); + const router = useRouter(); const active = computed(() => { @@ -76,15 +86,13 @@ function openWindow() { } function nav(ev: MouseEvent) { - if (props.behavior === 'browser') { + if (behavior === 'browser') { location.href = props.to; return; } - if (props.behavior) { - if (props.behavior === 'window') { - return openWindow(); - } + if (behavior === 'window') { + return openWindow(); } if (ev.shiftKey) { |