@@ -10,19 +10,19 @@ import { css, html, LitElement } from 'lit';
1010import { ifDefined } from 'lit/directives/if-defined.js' ;
1111import { defineCustomElement } from '@vaadin/component-base/src/define.js' ;
1212import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js' ;
13+ import { ContextMenuMixin } from '@vaadin/context-menu/src/vaadin-context-menu-mixin.js' ;
1314import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js' ;
14- import { SubMenuMixin } from './vaadin-menu-bar-submenu-mixin.js' ;
1515
1616/**
1717 * An element used internally by `<vaadin-menu-bar>`. Not intended to be used separately.
1818 *
1919 * @customElement
2020 * @extends HTMLElement
21- * @mixes SubMenuMixin
21+ * @mixes ContextMenuMixin
2222 * @mixes ThemePropertyMixin
2323 * @protected
2424 */
25- class MenuBarSubmenu extends SubMenuMixin ( ThemePropertyMixin ( PolylitMixin ( LitElement ) ) ) {
25+ class MenuBarSubmenu extends ContextMenuMixin ( ThemePropertyMixin ( PolylitMixin ( LitElement ) ) ) {
2626 static get is ( ) {
2727 return 'vaadin-menu-bar-submenu' ;
2828 }
@@ -39,6 +39,21 @@ class MenuBarSubmenu extends SubMenuMixin(ThemePropertyMixin(PolylitMixin(LitEle
3939 ` ;
4040 }
4141
42+ constructor ( ) {
43+ super ( ) ;
44+
45+ this . openOn = 'opensubmenu' ;
46+ }
47+
48+ /**
49+ * Tag name prefix used by overlay, list-box and items.
50+ * @protected
51+ * @return {string }
52+ */
53+ get _tagNamePrefix ( ) {
54+ return 'vaadin-menu-bar' ;
55+ }
56+
4257 /** @protected */
4358 render ( ) {
4459 return html `
@@ -61,6 +76,45 @@ class MenuBarSubmenu extends SubMenuMixin(ThemePropertyMixin(PolylitMixin(LitEle
6176 </ vaadin-menu-bar-overlay >
6277 ` ;
6378 }
79+
80+ /**
81+ * Overriding the observer to not add global "contextmenu" listener.
82+ * @override
83+ */
84+ _openedChanged ( ) {
85+ // Do nothing
86+ }
87+
88+ /**
89+ * Overriding the public method to reset expanded button state.
90+ */
91+ close ( ) {
92+ super . close ( ) ;
93+
94+ // Only handle 1st level submenu
95+ if ( this . hasAttribute ( 'is-root' ) ) {
96+ this . parentElement . _close ( ) ;
97+ }
98+ }
99+
100+ /**
101+ * Override method from `ContextMenuMixin` to prevent closing
102+ * sub-menu on the same click event that was used to open it.
103+ *
104+ * @param {Event } event
105+ * @return {boolean }
106+ * @protected
107+ * @override
108+ */
109+ _shouldCloseOnOutsideClick ( event ) {
110+ if ( this . hasAttribute ( 'is-root' ) && event . composedPath ( ) . includes ( this . listenOn ) ) {
111+ return false ;
112+ }
113+
114+ return super . _shouldCloseOnOutsideClick ( event ) ;
115+ }
64116}
65117
66118defineCustomElement ( MenuBarSubmenu ) ;
119+
120+ export { MenuBarSubmenu } ;
0 commit comments