Skip to content

Commit f45a7a0

Browse files
committed
Add clickCloseOnOutside allow do not close menu when the user click on other places (#76)
1 parent 4f312be commit f45a7a0

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

library/ContextMenuDefine.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ export interface MenuOptions {
124124
* If your element in menu item has this className, click it will ignore event.
125125
*/
126126
ignoreClickClassName?: string,
127+
/**
128+
* Set should close menu when the user click on other places.
129+
*
130+
* @default true
131+
*/
132+
clickCloseOnOutside ?: boolean;
127133
/**
128134
* If your element in menu item has this className, click it will ignore event and close hole menu.
129135
*/
@@ -206,12 +212,12 @@ export interface MenuOptions {
206212
* ```
207213
*/
208214
getContainer ?: HTMLElement | (() => HTMLElement);
215+
209216
/**
210217
* This event emit when this menu is closing. (Usually used in function mode)
211218
* @param lastClickItem The last clicked menu item, if user does not click any item, it is `undefined`. This param only valid in function mode.
212219
*/
213220
onClose ?: ((lastClickItem: MenuItem|undefined) => void) | undefined;
214-
215221
/**
216222
* Event for MenuBar component
217223
*/

library/ContextSubMenuWrapper.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,11 @@ export default defineComponent({
171171
return;
172172
target = target.parentNode as HTMLElement;
173173
}
174-
175-
//Close menu
176-
removeBodyEvents();
177-
closeMenu();
174+
if (options.value.clickCloseOnOutside !== false) {
175+
//Close menu
176+
removeBodyEvents();
177+
closeMenu();
178+
}
178179
}
179180
180181
//provide globalOptions for child use

0 commit comments

Comments
 (0)