@progress/kendo-vue-layout
Version:
102 lines (101 loc) • 3.08 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2026 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import { defineComponent as l, createVNode as i, nextTick as c, isVNode as d } from "vue";
import { getDefaultSlots as m, canUseDOM as r, getActiveElement as u } from "@progress/kendo-vue-common";
import { Popup as p } from "@progress/kendo-vue-popup";
import { Menu as f } from "../menu/components/Menu.mjs";
function h(e) {
return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !d(e);
}
const C = /* @__PURE__ */ l({
name: "KendoContextMenu",
props: {
show: {
type: Boolean,
default: !1
},
offset: {
type: Object,
default: () => ({
left: 0,
top: 0
})
},
items: {
type: Array,
default: void 0
},
dir: String,
itemRender: [String, Object, Function],
linkRender: [String, Object, Function],
customCloseItemIds: Array,
className: String
},
emits: ["close", "select"],
data() {
return {
visible: this.show
};
},
watch: {
show(e) {
this.visible = e, r && (e ? (c(() => {
var o;
const t = (o = this.$refs.popupRef) == null ? void 0 : o.$el, s = t == null ? void 0 : t.querySelector(".k-menu-item"), n = u(t == null ? void 0 : t.ownerDocument);
s && s !== n && s.focus();
}), document.addEventListener("mousedown", this.handleClickOutside)) : document.removeEventListener("mousedown", this.handleClickOutside));
}
},
unmounted() {
r && document.removeEventListener("mousedown", this.handleClickOutside);
},
methods: {
handleClose() {
this.$emit("close");
},
handleSelect(e) {
this.$emit("select", e);
},
handleClickOutside(e) {
var n, o;
const t = (n = this.$refs.popupRef) == null ? void 0 : n.$el, s = e.target;
if (t && !t.contains(s)) {
if ((o = s.closest) != null && o.call(s, ".k-menu-item"))
return;
this.handleClose();
}
}
},
render() {
var s;
let e;
const t = this.visible && ((s = this.$props.items) == null ? void 0 : s.length);
return i(p, {
ref: "popupRef",
show: !!t,
offset: this.$props.offset,
popupClass: "k-menu-popup k-overflow-visible"
}, {
default: () => [t ? i(f, {
vertical: !0,
items: this.$props.items,
dir: this.$props.dir,
itemRender: this.$props.itemRender,
linkRender: this.$props.linkRender,
customCloseItemIds: this.$props.customCloseItemIds,
class: ["k-context-menu", this.$props.className],
onSelect: this.handleSelect
}, h(e = m(this)) ? e : {
default: () => [e]
}) : void 0]
});
}
});
export {
C as ContextMenu
};