Skip to content

Commit

Permalink
Fixed #3158 - ContextMenu | does not close when left click outside of…
Browse files Browse the repository at this point in the history
… menu
  • Loading branch information
tugcekucukoglu committed Oct 26, 2022
1 parent 6eaabd8 commit 69066a3
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/components/contextmenu/ContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default {
this.bindOutsideClickListener();
this.bindResizeListener();
this.bindDocumentContextMenuListener();
} else {
} else if (!this.visible) {
this.unbindOutsideClickListener();
this.unbindResizeListener();
this.unbindDocumentContextMenuListener();
Expand Down Expand Up @@ -148,7 +148,7 @@ export default {
return processedItem && ObjectUtils.isNotEmpty(processedItem.items);
},
toggle(event) {
this.visible ? this.hide(event) : this.show(event);
this.visible ? this.hide() : this.show(event);
},
show(event) {
this.activeItemPath = [];
Expand Down Expand Up @@ -258,9 +258,8 @@ export default {
isFocus && DomHandler.focus(this.list);
},
onItemClick(event) {
const { originalEvent, processedItem } = event;
const { processedItem } = event;
const grouped = this.isProccessedItemGroup(processedItem);
const root = ObjectUtils.isEmpty(processedItem.parent);
const selected = this.isSelected(processedItem);
if (selected) {
Expand All @@ -271,7 +270,7 @@ export default {
DomHandler.focus(this.list);
} else {
grouped ? this.onItemChange(event) : this.hide(originalEvent, !root);
grouped ? this.onItemChange(event) : this.hide();
}
},
onItemMouseEnter(event) {
Expand All @@ -292,7 +291,7 @@ export default {
!grouped && this.onItemChange({ originalEvent: event, processedItem });
}
this.popup && this.hide(event, true);
this.popup && this.hide();
event.preventDefault();
} else {
const itemIndex = this.focusedItemInfo.index !== -1 ? this.findPrevItemIndex(this.focusedItemInfo.index) : this.findLastFocusedItemIndex();
Expand Down Expand Up @@ -355,7 +354,7 @@ export default {
this.onEnterKey(event);
},
onEscapeKey(event) {
this.hide(event, true);
this.hide();
!this.popup && (this.focusedItemInfo.index = this.findFirstFocusedItemIndex());
event.preventDefault();
Expand All @@ -372,8 +371,6 @@ export default {
},
onEnter(el) {
this.position();
this.bindOutsideClickListener();
this.bindResizeListener();
if (this.autoZIndex) {
ZIndexUtils.set('menu', el, this.baseZIndex + this.$primevue.config.zIndex.menu);
Expand All @@ -388,17 +385,17 @@ export default {
DomHandler.focus(this.list);
},
onLeave() {
this.unbindOutsideClickListener();
this.unbindResizeListener();
this.unbindDocumentContextMenuListener();
this.$emit('hide');
this.container = null;
},
onAfterLeave(el) {
if (this.autoZIndex) {
ZIndexUtils.clear(el);
}
this.unbindOutsideClickListener();
this.unbindResizeListener();
this.unbindDocumentContextMenuListener();
},
position() {
let left = this.pageX + 1;
Expand Down Expand Up @@ -452,9 +449,9 @@ export default {
},
bindResizeListener() {
if (!this.resizeListener) {
this.resizeListener = (event) => {
this.resizeListener = () => {
if (this.visible && !DomHandler.isTouchDevice()) {
this.hide(event, true);
this.hide();
}
};
Expand All @@ -470,7 +467,7 @@ export default {
bindDocumentContextMenuListener() {
if (!this.documentContextMenuListener) {
this.documentContextMenuListener = (event) => {
this.show(event);
event.button !== 2 ? this.show(event) : this.hide();
};
document.addEventListener('contextmenu', this.documentContextMenuListener);
Expand Down

0 comments on commit 69066a3

Please sign in to comment.