File tree Expand file tree Collapse file tree 4 files changed +53
-2
lines changed Expand file tree Collapse file tree 4 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ export const ItemsMixin = (superClass) =>
69
69
// Overlay's outside click listener doesn't work with modeless
70
70
// overlays (submenus) so we need additional logic for it
71
71
this . __itemsOutsideClickListener = ( e ) => {
72
- if ( ! e . composedPath ( ) . some ( ( el ) => el . localName === ` ${ this . _tagNamePrefix } -overlay` ) ) {
72
+ if ( this . _shouldCloseOnOutsideClick ( e ) ) {
73
73
this . dispatchEvent ( new CustomEvent ( 'items-outside-click' ) ) ;
74
74
}
75
75
} ;
@@ -101,6 +101,18 @@ export const ItemsMixin = (superClass) =>
101
101
document . documentElement . removeEventListener ( 'click' , this . __itemsOutsideClickListener ) ;
102
102
}
103
103
104
+ /**
105
+ * Whether to close the overlay on outside click or not.
106
+ * Override this method to customize the closing logic.
107
+ *
108
+ * @param {Event } event
109
+ * @return {boolean }
110
+ * @protected
111
+ */
112
+ _shouldCloseOnOutsideClick ( event ) {
113
+ return ! event . composedPath ( ) . some ( ( el ) => el . localName === `${ this . _tagNamePrefix } -overlay` ) ;
114
+ }
115
+
104
116
/** @protected */
105
117
__forwardFocus ( ) {
106
118
const overlay = this . _overlayElement ;
Original file line number Diff line number Diff line change @@ -904,7 +904,6 @@ export const MenuBarMixin = (superClass) =>
904
904
905
905
/** @private */
906
906
__onButtonClick ( e ) {
907
- e . stopPropagation ( ) ;
908
907
const button = this . _getButtonFromEvent ( e ) ;
909
908
if ( button ) {
910
909
this . __openSubMenu ( button , button . __triggeredWithActiveKeys ) ;
Original file line number Diff line number Diff line change @@ -46,4 +46,21 @@ export const SubMenuMixin = (superClass) =>
46
46
this . getRootNode ( ) . host . _close ( ) ;
47
47
}
48
48
}
49
+
50
+ /**
51
+ * Override method from `ContextMenuMixin` to prevent closing
52
+ * sub-menu on the same click event that was used to open it.
53
+ *
54
+ * @param {Event } event
55
+ * @return {boolean }
56
+ * @protected
57
+ * @override
58
+ */
59
+ _shouldCloseOnOutsideClick ( event ) {
60
+ if ( this . hasAttribute ( 'is-root' ) && event . composedPath ( ) . includes ( this . listenOn ) ) {
61
+ return false ;
62
+ }
63
+
64
+ return super . _shouldCloseOnOutsideClick ( event ) ;
65
+ }
49
66
} ;
Original file line number Diff line number Diff line change @@ -94,6 +94,29 @@ describe('sub-menu', () => {
94
94
expect ( spy . calledOnce ) . to . be . true ;
95
95
} ) ;
96
96
97
+ it ( 'should set pointer events to `auto` when opened on click' , async ( ) => {
98
+ buttons [ 0 ] . click ( ) ;
99
+ await nextRender ( subMenu ) ;
100
+ expect ( menu . style . pointerEvents ) . to . equal ( 'auto' ) ;
101
+ } ) ;
102
+
103
+ it ( 'should reset pointer events after closing on click' , async ( ) => {
104
+ buttons [ 0 ] . click ( ) ;
105
+ await nextRender ( subMenu ) ;
106
+
107
+ buttons [ 0 ] . click ( ) ;
108
+ await nextRender ( subMenu ) ;
109
+ expect ( menu . style . pointerEvents ) . to . be . empty ;
110
+ } ) ;
111
+
112
+ it ( 'should not stop click event from propagating when opened ' , async ( ) => {
113
+ const event = new CustomEvent ( 'click' , { bubbles : true } ) ;
114
+ const spy = sinon . spy ( event , 'stopPropagation' ) ;
115
+ buttons [ 0 ] . dispatchEvent ( event ) ;
116
+ await nextRender ( subMenu ) ;
117
+ expect ( spy . called ) . to . be . false ;
118
+ } ) ;
119
+
97
120
it ( 'should focus the overlay when sub-menu opened on click' , async ( ) => {
98
121
const spy = sinon . spy ( subMenuOverlay . $ . overlay , 'focus' ) ;
99
122
buttons [ 0 ] . click ( ) ;
You can’t perform that action at this time.
0 commit comments