Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## Added

- **ContextMenu**: Added `preventClose` property.

## Fixed

- **ContextMenu**: `show` attribute was not synchronized correctly.
Expand Down
18 changes: 15 additions & 3 deletions src/vscode-context-menu/vscode-context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export class VscodeContextMenu extends VscElement {
return this._data;
}

/**
* By default, the menu closes when an item is clicked. This attribute prevents the menu from closing.
*/
@property({type: Boolean, reflect: true, attribute: 'prevent-close'})
preventClose = false;

@property({type: Boolean, reflect: true})
set show(show: boolean) {
this._show = show;
Expand Down Expand Up @@ -223,16 +229,22 @@ export class VscodeContextMenu extends VscElement {

this._dispatchLegacySelectEvent(selectedOption);
this._dispatchSelectEvent(selectedOption);
this.show = false;
document.removeEventListener('click', this._onClickOutsideBound);

if (!this.preventClose) {
this.show = false;
document.removeEventListener('click', this._onClickOutsideBound);
}
}

private _onItemClick(event: CustomEvent) {
const et = event.currentTarget as VscodeContextMenuItem;

this._dispatchLegacySelectEvent(et);
this._dispatchSelectEvent(et);
this.show = false;

if (!this.preventClose) {
this.show = false;
}
}

private _onItemMouseOver(event: MouseEvent) {
Expand Down