2
0
mirror of https://github.com/tenrok/vue-context.git synced 2026-06-24 04:40:33 +03:00

Emit close and open events

This commit is contained in:
Randall Wilk
2018-10-15 08:55:20 -05:00
parent 640980b8bf
commit d157ffc746
2 changed files with 13 additions and 5 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+12 -4
View File
@@ -45,7 +45,7 @@
return this.show return this.show
? { top: `${this.top}px`, left: `${this.left}px` } ? { top: `${this.top}px`, left: `${this.left}px` }
: null; : null;
}, }
}, },
data () { data () {
@@ -79,12 +79,18 @@
/** /**
* Close the context menu. * Close the context menu.
*
* @param {boolean|Event} emit Used to prevent event being emitted twice from when menu is clicked and closed
*/ */
close () { close (emit = true) {
this.top = null; this.top = null;
this.left = null; this.left = null;
this.data = null; this.data = null;
this.show = false; this.show = false;
if (emit) {
this.$emit('close');
}
}, },
/** /**
@@ -92,7 +98,7 @@
*/ */
onClick () { onClick () {
if (this.closeOnClick) { if (this.closeOnClick) {
this.close(); this.close(false);
} }
}, },
@@ -109,6 +115,8 @@
this.$nextTick(() => { this.$nextTick(() => {
this.positionMenu(event.clientY, event.clientX); this.positionMenu(event.clientY, event.clientX);
this.$el.focus(); this.$el.focus();
this.$emit('open', event, this.data, this.top, this.left);
}); });
}, },
@@ -200,4 +208,4 @@
} }
} }
} }
</style> </style>