Skip to content

Commit 7d34f2e

Browse files
[6.x] Add as prop to ContextItem component (#13389)
Co-authored-by: Jason Varga <[email protected]>
1 parent 9859348 commit 7d34f2e

File tree

1 file changed

+10
-2
lines changed
  • resources/js/components/ui/Context

1 file changed

+10
-2
lines changed

resources/js/components/ui/Context/Item.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<script setup>
22
import { ContextMenuItem } from 'reka-ui';
3-
import { useSlots } from 'vue';
3+
import { computed, useSlots } from 'vue';
44
import Icon from '../Icon/Icon.vue';
55
import { cva } from 'cva';
6+
import { Link } from "@inertiajs/vue3";
67
78
const props = defineProps({
9+
/** The element or component this component should render as */
10+
as: { type: String, default: null },
811
/** The URL to link to */
912
href: { type: String, default: null },
1013
/** When `href` is provided, this prop controls the link's `target` attribute */
@@ -19,6 +22,11 @@ const props = defineProps({
1922
2023
const slots = useSlots();
2124
const hasDefaultSlot = !!slots.default;
25+
const tag = computed(() => {
26+
if (props.as) return props.as;
27+
if (! props.href) return 'div';
28+
return props.target === '_blank' ? 'a' : Link;
29+
});
2230
2331
const classes = cva({
2432
base: [
@@ -51,7 +59,7 @@ const iconClasses = cva({
5159
<ContextMenuItem
5260
:class="classes"
5361
data-ui-context-item
54-
:as="href ? 'a' : 'div'"
62+
:as="tag"
5563
:href
5664
:target
5765
>

0 commit comments

Comments
 (0)