@@ -87,7 +87,41 @@ describe('Mousetrap.bind', function () {
87
87
}
88
88
} ) ;
89
89
90
- it ( 'keyup events should fire' , function ( ) {
90
+ it ( 'z key does not fire when inside an input element in an open shadow dom' , function ( ) {
91
+ var spy = sinon . spy ( ) ;
92
+
93
+ var shadowHost = document . createElement ( 'div' ) ;
94
+ var shadowRoot = shadowHost . attachShadow ( { mode : 'open' } ) ;
95
+ document . body . appendChild ( shadowHost ) ;
96
+
97
+ var inputElement = document . createElement ( 'input' ) ;
98
+ shadowRoot . appendChild ( inputElement ) ;
99
+ expect ( shadowHost . shadowRoot ) . to . equal ( shadowRoot , 'shadow root accessible' ) ;
100
+
101
+ Mousetrap . bind ( 'z' , spy ) ;
102
+ KeyEvent . simulate ( 'Z' . charCodeAt ( 0 ) , 90 , [ ] , inputElement , 1 , { shadowHost : shadowHost } ) ;
103
+ document . body . removeChild ( shadowHost ) ;
104
+ expect ( spy . callCount ) . to . equal ( 0 , 'callback should not have fired' ) ;
105
+ } ) ;
106
+
107
+ it ( 'z key does fire when inside an input element in a closed shadow dom' , function ( ) {
108
+ var spy = sinon . spy ( ) ;
109
+
110
+ var shadowHost = document . createElement ( 'div' ) ;
111
+ var shadowRoot = shadowHost . attachShadow ( { mode : 'closed' } ) ;
112
+ document . body . appendChild ( shadowHost ) ;
113
+
114
+ var inputElement = document . createElement ( 'input' ) ;
115
+ shadowRoot . appendChild ( inputElement ) ;
116
+ expect ( shadowHost . shadowRoot ) . to . equal ( null , 'shadow root unaccessible' ) ;
117
+
118
+ Mousetrap . bind ( 'z' , spy ) ;
119
+ KeyEvent . simulate ( 'Z' . charCodeAt ( 0 ) , 90 , [ ] , inputElement , 1 , { shadowHost : shadowHost } ) ;
120
+ document . body . removeChild ( shadowHost ) ;
121
+ expect ( spy . callCount ) . to . equal ( 1 , 'callback should have fired once' ) ;
122
+ } ) ;
123
+
124
+ it ( 'keyup events should fire' , function ( ) {
91
125
var spy = sinon . spy ( ) ;
92
126
93
127
Mousetrap . bind ( 'z' , spy , 'keyup' ) ;
0 commit comments