aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/components/PublicPageMenu/PublicPageMenuEntry.vue
blob: 4a8640f38a8d0516e509c36e98f548413a065d1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!--
 - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 - SPDX-License-Identifier: AGPL-3.0-or-later
 -->
<template>
	<NcListItem :anchor-id="`${id}--link`"
		compact
		:details="details"
		:href="href"
		:name="label"
		role="presentation"
		@click="$emit('click')">
		<template #icon>
			<div role="presentation" :class="['icon', icon, 'public-page-menu-entry__icon']" />
		</template>
	</NcListItem>
</template>

<script setup lang="ts">
import NcListItem from '@nextcloud/vue/components/NcListItem'
import { onMounted } from 'vue'

const props = defineProps<{
	/** Only emit click event but do not open href */
	clickOnly?: boolean
	// menu entry props
	id: string
	label: string
	icon: string
	href: string
	details?: string
}>()

onMounted(() => {
	const anchor = document.getElementById(`${props.id}--link`) as HTMLAnchorElement
	// Make the `<a>` a menuitem
	anchor.role = 'menuitem'
	// Prevent native click handling if required
	if (props.clickOnly) {
		anchor.onclick = (event) => event.preventDefault()
	}
})
</script>

<style scoped>
.public-page-menu-entry__icon {
	padding-inline-start: var(--default-grid-baseline);
}
</style>