@spectrum-web-components/menu 0.12.4 → 0.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,487 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import '../sp-menu.js';
13
+ import '../sp-menu-item.js';
14
+ import { elementUpdated, expect, fixture, html, nextFrame, oneEvent, } from '@open-wc/testing';
15
+ import '@spectrum-web-components/theme/sp-theme.js';
16
+ import '@spectrum-web-components/theme/src/themes.js';
17
+ import { sendMouse } from '../../../test/plugins/browser.js';
18
+ import { spy } from 'sinon';
19
+ import { sendKeys } from '@web/test-runner-commands';
20
+ async function styledFixture(story, dir = 'ltr') {
21
+ const test = await fixture(html `
22
+ <sp-theme dir=${dir} scale="medium" color="dark">${story}</sp-theme>
23
+ `);
24
+ document.documentElement.dir = dir;
25
+ return test.children[0];
26
+ }
27
+ describe('Submenu', () => {
28
+ it('selects - pointer', async () => {
29
+ const rootChanged = spy();
30
+ const submenuChanged = spy();
31
+ const el = await styledFixture(html `
32
+ <sp-menu
33
+ @change=${(event) => {
34
+ rootChanged(event.target.value);
35
+ }}
36
+ >
37
+ <sp-menu-item class="root">
38
+ Has submenu
39
+ <sp-menu
40
+ slot="submenu"
41
+ @change=${(event) => {
42
+ submenuChanged(event.target.value);
43
+ }}
44
+ >
45
+ <sp-menu-item class="submenu-item-1">
46
+ One
47
+ </sp-menu-item>
48
+ <sp-menu-item class="submenu-item-2">
49
+ Two
50
+ </sp-menu-item>
51
+ <sp-menu-item class="submenu-item-3">
52
+ Three
53
+ </sp-menu-item>
54
+ </sp-menu>
55
+ </sp-menu-item>
56
+ </sp-menu>
57
+ `);
58
+ await elementUpdated(el);
59
+ const rootItem = el.querySelector('.root');
60
+ const rootItemBoundingRect = rootItem.getBoundingClientRect();
61
+ expect(rootItem.open).to.be.false;
62
+ const opened = oneEvent(rootItem, 'sp-opened');
63
+ sendMouse({
64
+ steps: [
65
+ {
66
+ type: 'move',
67
+ position: [
68
+ rootItemBoundingRect.left +
69
+ rootItemBoundingRect.width / 2,
70
+ rootItemBoundingRect.top +
71
+ rootItemBoundingRect.height / 2,
72
+ ],
73
+ },
74
+ ],
75
+ });
76
+ await opened;
77
+ expect(rootItem.open).to.be.true;
78
+ const item2 = document.querySelector('.submenu-item-2');
79
+ const item2BoundingRect = item2.getBoundingClientRect();
80
+ const closed = oneEvent(rootItem, 'sp-closed');
81
+ sendMouse({
82
+ steps: [
83
+ {
84
+ type: 'click',
85
+ position: [
86
+ item2BoundingRect.left + item2BoundingRect.width / 2,
87
+ item2BoundingRect.top + item2BoundingRect.height / 2,
88
+ ],
89
+ },
90
+ ],
91
+ });
92
+ await closed;
93
+ await nextFrame();
94
+ expect(rootChanged.calledWith('Has submenu'), 'root changed').to.be
95
+ .true;
96
+ expect(submenuChanged.calledWith('Two'), 'submenu changed').to.be.true;
97
+ });
98
+ it('closes deep tree on selection', async () => {
99
+ const rootChanged = spy();
100
+ const submenuChanged = spy();
101
+ const subSubmenuChanged = spy();
102
+ const el = await styledFixture(html `
103
+ <sp-menu
104
+ @change=${(event) => {
105
+ rootChanged(event.target.value);
106
+ }}
107
+ >
108
+ <sp-menu-item class="root">
109
+ Has submenu
110
+ <sp-menu
111
+ slot="submenu"
112
+ @change=${(event) => {
113
+ submenuChanged(event.target.value);
114
+ }}
115
+ >
116
+ <sp-menu-item class="submenu-item-1">
117
+ One
118
+ </sp-menu-item>
119
+ <sp-menu-item class="submenu-item-2">
120
+ Two
121
+ <sp-menu
122
+ slot="submenu"
123
+ @change=${(event) => {
124
+ subSubmenuChanged(event.target.value);
125
+ }}
126
+ >
127
+ <sp-menu-item class="sub-submenu-item-1">
128
+ A
129
+ </sp-menu-item>
130
+ <sp-menu-item class="sub-submenu-item-2">
131
+ B
132
+ </sp-menu-item>
133
+ <sp-menu-item class="sub-submenu-item-3">
134
+ C
135
+ </sp-menu-item>
136
+ </sp-menu>
137
+ </sp-menu-item>
138
+ <sp-menu-item class="submenu-item-3">
139
+ Three
140
+ </sp-menu-item>
141
+ </sp-menu>
142
+ </sp-menu-item>
143
+ </sp-menu>
144
+ `);
145
+ await elementUpdated(el);
146
+ const rootItem = el.querySelector('.root');
147
+ const rootItemBoundingRect = rootItem.getBoundingClientRect();
148
+ expect(rootItem.open).to.be.false;
149
+ const opened = oneEvent(rootItem, 'sp-opened');
150
+ sendMouse({
151
+ steps: [
152
+ {
153
+ type: 'move',
154
+ position: [
155
+ rootItemBoundingRect.left +
156
+ rootItemBoundingRect.width / 2,
157
+ rootItemBoundingRect.top +
158
+ rootItemBoundingRect.height / 2,
159
+ ],
160
+ },
161
+ ],
162
+ });
163
+ await opened;
164
+ expect(rootItem.open).to.be.true;
165
+ const item2 = document.querySelector('.submenu-item-2');
166
+ const item2BoundingRect = item2.getBoundingClientRect();
167
+ let closed = oneEvent(item2, 'sp-opened');
168
+ sendMouse({
169
+ steps: [
170
+ {
171
+ type: 'click',
172
+ position: [
173
+ item2BoundingRect.left + item2BoundingRect.width / 2,
174
+ item2BoundingRect.top + item2BoundingRect.height / 2,
175
+ ],
176
+ },
177
+ ],
178
+ });
179
+ await closed;
180
+ await nextFrame();
181
+ expect(item2.open).to.be.true;
182
+ const itemC = document.querySelector('.sub-submenu-item-3');
183
+ const itemCBoundingRect = itemC.getBoundingClientRect();
184
+ closed = oneEvent(rootItem, 'sp-closed');
185
+ sendMouse({
186
+ steps: [
187
+ {
188
+ type: 'click',
189
+ position: [
190
+ itemCBoundingRect.left + itemCBoundingRect.width / 2,
191
+ itemCBoundingRect.top + itemCBoundingRect.height / 2,
192
+ ],
193
+ },
194
+ ],
195
+ });
196
+ await closed;
197
+ await nextFrame();
198
+ expect(rootChanged.calledWith('Has submenu'), 'root changed').to.be
199
+ .true;
200
+ expect(submenuChanged.calledWith('Two'), 'submenu changed').to.be.true;
201
+ expect(subSubmenuChanged.calledWith('C'), 'sub submenu changed').to.be
202
+ .true;
203
+ });
204
+ [
205
+ {
206
+ dir: 'ltr',
207
+ openKey: 'ArrowRight',
208
+ closeKey: 'ArrowLeft',
209
+ },
210
+ {
211
+ dir: 'rtl',
212
+ openKey: 'ArrowLeft',
213
+ closeKey: 'ArrowRight',
214
+ },
215
+ ].map((testData) => {
216
+ it(`selects - keyboard: ${testData.dir}`, async () => {
217
+ const rootChanged = spy();
218
+ const submenuChanged = spy();
219
+ const el = await styledFixture(html `
220
+ <sp-menu
221
+ @change=${(event) => {
222
+ rootChanged(event.target.value);
223
+ }}
224
+ >
225
+ <sp-menu-item class="root">
226
+ Has submenu
227
+ <sp-menu
228
+ slot="submenu"
229
+ @change=${(event) => {
230
+ submenuChanged(event.target.value);
231
+ }}
232
+ >
233
+ <sp-menu-item class="submenu-item-1">
234
+ One
235
+ </sp-menu-item>
236
+ <sp-menu-item class="submenu-item-2">
237
+ Two
238
+ </sp-menu-item>
239
+ <sp-menu-item class="submenu-item-3">
240
+ Three
241
+ </sp-menu-item>
242
+ </sp-menu>
243
+ </sp-menu-item>
244
+ </sp-menu>
245
+ `, testData.dir);
246
+ await elementUpdated(el);
247
+ const rootItem = el.querySelector('.root');
248
+ expect(rootItem.open).to.be.false;
249
+ el.focus();
250
+ await elementUpdated(el);
251
+ let opened = oneEvent(rootItem, 'sp-opened');
252
+ sendKeys({
253
+ press: testData.openKey,
254
+ });
255
+ await opened;
256
+ expect(rootItem.open).to.be.true;
257
+ let closed = oneEvent(rootItem, 'sp-closed');
258
+ sendKeys({
259
+ press: testData.closeKey,
260
+ });
261
+ await closed;
262
+ expect(rootItem.open).to.be.false;
263
+ opened = oneEvent(rootItem, 'sp-opened');
264
+ sendKeys({
265
+ press: testData.openKey,
266
+ });
267
+ await opened;
268
+ expect(rootItem.open).to.be.true;
269
+ await sendKeys({
270
+ press: 'ArrowDown',
271
+ });
272
+ closed = oneEvent(rootItem, 'sp-closed');
273
+ sendKeys({
274
+ press: 'Enter',
275
+ });
276
+ await closed;
277
+ expect(rootChanged.calledWith('Has submenu'), 'root changed').to.be
278
+ .true;
279
+ expect(submenuChanged.calledWith('Two'), 'submenu changed').to.be
280
+ .true;
281
+ });
282
+ });
283
+ it('closes on `pointerleave`', async () => {
284
+ const el = await styledFixture(html `
285
+ <sp-menu>
286
+ <sp-menu-item class="root">
287
+ Has submenu
288
+ <sp-menu slot="submenu">
289
+ <sp-menu-item class="submenu-item-1">
290
+ One
291
+ </sp-menu-item>
292
+ <sp-menu-item class="submenu-item-2">
293
+ Two
294
+ </sp-menu-item>
295
+ <sp-menu-item class="submenu-item-3">
296
+ Three
297
+ </sp-menu-item>
298
+ </sp-menu>
299
+ </sp-menu-item>
300
+ </sp-menu>
301
+ `);
302
+ await elementUpdated(el);
303
+ const rootItem = el.querySelector('.root');
304
+ const rootItemBoundingRect = rootItem.getBoundingClientRect();
305
+ expect(rootItem.open).to.be.false;
306
+ const opened = oneEvent(rootItem, 'sp-opened');
307
+ sendMouse({
308
+ steps: [
309
+ {
310
+ type: 'move',
311
+ position: [
312
+ rootItemBoundingRect.left +
313
+ rootItemBoundingRect.width / 2,
314
+ rootItemBoundingRect.top +
315
+ rootItemBoundingRect.height / 2,
316
+ ],
317
+ },
318
+ ],
319
+ });
320
+ await opened;
321
+ expect(rootItem.open).to.be.true;
322
+ const closed = oneEvent(rootItem, 'sp-closed');
323
+ sendMouse({
324
+ steps: [
325
+ {
326
+ type: 'move',
327
+ position: [
328
+ rootItemBoundingRect.left +
329
+ rootItemBoundingRect.width / 2,
330
+ rootItemBoundingRect.top +
331
+ rootItemBoundingRect.height * 2,
332
+ ],
333
+ },
334
+ ],
335
+ });
336
+ await closed;
337
+ expect(rootItem.open).to.be.false;
338
+ });
339
+ it('stays open when mousing off menu item and back again', async () => {
340
+ const el = await styledFixture(html `
341
+ <sp-menu>
342
+ <sp-menu-item class="root">
343
+ Has submenu
344
+ <sp-menu slot="submenu">
345
+ <sp-menu-item class="submenu-item-1">
346
+ One
347
+ </sp-menu-item>
348
+ <sp-menu-item class="submenu-item-2">
349
+ Two
350
+ </sp-menu-item>
351
+ <sp-menu-item class="submenu-item-3">
352
+ Three
353
+ </sp-menu-item>
354
+ </sp-menu>
355
+ </sp-menu-item>
356
+ </sp-menu>
357
+ `);
358
+ await elementUpdated(el);
359
+ const rootItem = el.querySelector('.root');
360
+ const rootItemBoundingRect = rootItem.getBoundingClientRect();
361
+ expect(rootItem.open).to.be.false;
362
+ const opened = oneEvent(rootItem, 'sp-opened');
363
+ await sendMouse({
364
+ steps: [
365
+ {
366
+ type: 'move',
367
+ position: [
368
+ rootItemBoundingRect.left +
369
+ rootItemBoundingRect.width / 2,
370
+ rootItemBoundingRect.top +
371
+ rootItemBoundingRect.height / 2,
372
+ ],
373
+ },
374
+ ],
375
+ });
376
+ await sendMouse({
377
+ steps: [
378
+ {
379
+ type: 'move',
380
+ position: [
381
+ rootItemBoundingRect.left +
382
+ rootItemBoundingRect.width / 2,
383
+ rootItemBoundingRect.top +
384
+ rootItemBoundingRect.height * 2,
385
+ ],
386
+ },
387
+ ],
388
+ });
389
+ await sendMouse({
390
+ steps: [
391
+ {
392
+ type: 'move',
393
+ position: [
394
+ rootItemBoundingRect.left +
395
+ rootItemBoundingRect.width / 2,
396
+ rootItemBoundingRect.top +
397
+ rootItemBoundingRect.height / 2,
398
+ ],
399
+ },
400
+ ],
401
+ });
402
+ await opened;
403
+ expect(rootItem.open).to.be.true;
404
+ const closed = oneEvent(rootItem, 'sp-closed');
405
+ sendMouse({
406
+ steps: [
407
+ {
408
+ type: 'move',
409
+ position: [
410
+ rootItemBoundingRect.left +
411
+ rootItemBoundingRect.width / 2,
412
+ rootItemBoundingRect.top +
413
+ rootItemBoundingRect.height * 2,
414
+ ],
415
+ },
416
+ ],
417
+ });
418
+ await closed;
419
+ });
420
+ it('stays open when mousing between menu item and submenu', async () => {
421
+ const el = await styledFixture(html `
422
+ <sp-menu>
423
+ <sp-menu-item class="root">
424
+ Has submenu
425
+ <sp-menu slot="submenu">
426
+ <sp-menu-item class="submenu-item-1">
427
+ One
428
+ </sp-menu-item>
429
+ <sp-menu-item class="submenu-item-2">
430
+ Two
431
+ </sp-menu-item>
432
+ <sp-menu-item class="submenu-item-3">
433
+ Three
434
+ </sp-menu-item>
435
+ </sp-menu>
436
+ </sp-menu-item>
437
+ </sp-menu>
438
+ `);
439
+ await elementUpdated(el);
440
+ const rootItem = el.querySelector('.root');
441
+ const rootItemBoundingRect = rootItem.getBoundingClientRect();
442
+ expect(rootItem.open).to.be.false;
443
+ const opened = oneEvent(rootItem, 'sp-opened');
444
+ await sendMouse({
445
+ steps: [
446
+ {
447
+ type: 'move',
448
+ position: [
449
+ rootItemBoundingRect.left +
450
+ rootItemBoundingRect.width / 2,
451
+ rootItemBoundingRect.top +
452
+ rootItemBoundingRect.height / 2,
453
+ ],
454
+ },
455
+ ],
456
+ });
457
+ await sendMouse({
458
+ steps: [
459
+ {
460
+ type: 'move',
461
+ position: [
462
+ rootItemBoundingRect.left +
463
+ rootItemBoundingRect.width / 2,
464
+ rootItemBoundingRect.top +
465
+ rootItemBoundingRect.height * 2,
466
+ ],
467
+ },
468
+ ],
469
+ });
470
+ await sendMouse({
471
+ steps: [
472
+ {
473
+ type: 'move',
474
+ position: [
475
+ rootItemBoundingRect.left +
476
+ rootItemBoundingRect.width * 1.5,
477
+ rootItemBoundingRect.top +
478
+ rootItemBoundingRect.height / 2,
479
+ ],
480
+ },
481
+ ],
482
+ });
483
+ await opened;
484
+ expect(rootItem.open).to.be.true;
485
+ });
486
+ });
487
+ //# sourceMappingURL=submenu.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3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C,EAAE,CAAC,KAAK,CAAC;QAElC,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC/C,MAAM,SAAS,CAAC;YACZ,KAAK,EAAE;gBACH;oBACI,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE;wBACN,oBAAoB,CAAC,IAAI;4BACrB,oBAAoB,CAAC,KAAK,GAAG,CAAC;wBAClC,oBAAoB,CAAC,GAAG;4BACpB,oBAAoB,CAAC,MAAM,GAAG,CAAC;qBACtC;iBACJ;aACJ;SACJ,CAAC,CAAC;QACH,MAAM,SAAS,CAAC;YACZ,KAAK,EAAE;gBACH;oBACI,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE;wBACN,oBAAoB,CAAC,IAAI;4BACrB,oBAAoB,CAAC,KAAK,GAAG,CAAC;wBAClC,oBAAoB,CAAC,GAAG;4BACpB,oBAAoB,CAAC,MAAM,GAAG,CAAC;qBACtC;iBACJ;aACJ;SACJ,CAAC,CAAC;QACH,MAAM,SAAS,CAAC;YACZ,KAAK,EAAE;gBACH;oBACI,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE;wBACN,oBAAoB,CAAC,IAAI;4BACrB,oBAAoB,CAAC,KAAK,GAAG,GAAG;wBACpC,oBAAoB,CAAC,GAAG;4BACpB,oBAAoB,CAAC,MAAM,GAAG,CAAC;qBACtC;iBACJ;aACJ;SACJ,CAAC,CAAC;QACH,MAAM,MAAM,CAAC;QAEb,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACrC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '../sp-menu.js';\nimport '../sp-menu-item.js';\nimport { Menu, MenuItem } from '@spectrum-web-components/menu';\nimport {\n elementUpdated,\n expect,\n fixture,\n html,\n nextFrame,\n oneEvent,\n} from '@open-wc/testing';\nimport '@spectrum-web-components/theme/sp-theme.js';\nimport '@spectrum-web-components/theme/src/themes.js';\nimport { sendMouse } from '../../../test/plugins/browser.js';\nimport { spy } from 'sinon';\nimport { Theme } from '@spectrum-web-components/theme';\nimport { TemplateResult } from '@spectrum-web-components/base';\nimport { sendKeys } from '@web/test-runner-commands';\n\nasync function styledFixture<T extends Element>(\n story: TemplateResult,\n dir: 'ltr' | 'rtl' | 'auto' = 'ltr'\n): Promise<T> {\n const test = await fixture<Theme>(html`\n <sp-theme dir=${dir} scale=\"medium\" color=\"dark\">${story}</sp-theme>\n `);\n document.documentElement.dir = dir;\n return test.children[0] as T;\n}\n\ndescribe('Submenu', () => {\n it('selects - pointer', async () => {\n const rootChanged = spy();\n const submenuChanged = spy();\n const el = await styledFixture<Menu>(\n html`\n <sp-menu\n @change=${(event: Event & { target: Menu }) => {\n rootChanged(event.target.value);\n }}\n >\n <sp-menu-item class=\"root\">\n Has submenu\n <sp-menu\n slot=\"submenu\"\n @change=${(event: Event & { target: Menu }) => {\n submenuChanged(event.target.value);\n }}\n >\n <sp-menu-item class=\"submenu-item-1\">\n One\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-2\">\n Two\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-3\">\n Three\n </sp-menu-item>\n </sp-menu>\n </sp-menu-item>\n </sp-menu>\n `\n );\n\n await elementUpdated(el);\n const rootItem = el.querySelector('.root') as MenuItem;\n const rootItemBoundingRect = rootItem.getBoundingClientRect();\n expect(rootItem.open).to.be.false;\n\n const opened = oneEvent(rootItem, 'sp-opened');\n sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height / 2,\n ],\n },\n ],\n });\n await opened;\n\n expect(rootItem.open).to.be.true;\n\n const item2 = document.querySelector('.submenu-item-2') as MenuItem;\n const item2BoundingRect = item2.getBoundingClientRect();\n\n const closed = oneEvent(rootItem, 'sp-closed');\n sendMouse({\n steps: [\n {\n type: 'click',\n position: [\n item2BoundingRect.left + item2BoundingRect.width / 2,\n item2BoundingRect.top + item2BoundingRect.height / 2,\n ],\n },\n ],\n });\n await closed;\n await nextFrame();\n\n expect(rootChanged.calledWith('Has submenu'), 'root changed').to.be\n .true;\n expect(submenuChanged.calledWith('Two'), 'submenu changed').to.be.true;\n });\n it('closes deep tree on selection', async () => {\n const rootChanged = spy();\n const submenuChanged = spy();\n const subSubmenuChanged = spy();\n const el = await styledFixture<Menu>(\n html`\n <sp-menu\n @change=${(event: Event & { target: Menu }) => {\n rootChanged(event.target.value);\n }}\n >\n <sp-menu-item class=\"root\">\n Has submenu\n <sp-menu\n slot=\"submenu\"\n @change=${(event: Event & { target: Menu }) => {\n submenuChanged(event.target.value);\n }}\n >\n <sp-menu-item class=\"submenu-item-1\">\n One\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-2\">\n Two\n <sp-menu\n slot=\"submenu\"\n @change=${(\n event: Event & { target: Menu }\n ) => {\n subSubmenuChanged(event.target.value);\n }}\n >\n <sp-menu-item class=\"sub-submenu-item-1\">\n A\n </sp-menu-item>\n <sp-menu-item class=\"sub-submenu-item-2\">\n B\n </sp-menu-item>\n <sp-menu-item class=\"sub-submenu-item-3\">\n C\n </sp-menu-item>\n </sp-menu>\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-3\">\n Three\n </sp-menu-item>\n </sp-menu>\n </sp-menu-item>\n </sp-menu>\n `\n );\n\n await elementUpdated(el);\n const rootItem = el.querySelector('.root') as MenuItem;\n const rootItemBoundingRect = rootItem.getBoundingClientRect();\n expect(rootItem.open).to.be.false;\n\n const opened = oneEvent(rootItem, 'sp-opened');\n sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height / 2,\n ],\n },\n ],\n });\n await opened;\n\n expect(rootItem.open).to.be.true;\n\n const item2 = document.querySelector('.submenu-item-2') as MenuItem;\n const item2BoundingRect = item2.getBoundingClientRect();\n\n let closed = oneEvent(item2, 'sp-opened');\n sendMouse({\n steps: [\n {\n type: 'click',\n position: [\n item2BoundingRect.left + item2BoundingRect.width / 2,\n item2BoundingRect.top + item2BoundingRect.height / 2,\n ],\n },\n ],\n });\n await closed;\n await nextFrame();\n\n expect(item2.open).to.be.true;\n\n const itemC = document.querySelector('.sub-submenu-item-3') as MenuItem;\n const itemCBoundingRect = itemC.getBoundingClientRect();\n\n closed = oneEvent(rootItem, 'sp-closed');\n sendMouse({\n steps: [\n {\n type: 'click',\n position: [\n itemCBoundingRect.left + itemCBoundingRect.width / 2,\n itemCBoundingRect.top + itemCBoundingRect.height / 2,\n ],\n },\n ],\n });\n await closed;\n await nextFrame();\n\n expect(rootChanged.calledWith('Has submenu'), 'root changed').to.be\n .true;\n expect(submenuChanged.calledWith('Two'), 'submenu changed').to.be.true;\n expect(subSubmenuChanged.calledWith('C'), 'sub submenu changed').to.be\n .true;\n });\n (\n [\n {\n dir: 'ltr',\n openKey: 'ArrowRight',\n closeKey: 'ArrowLeft',\n },\n {\n dir: 'rtl',\n openKey: 'ArrowLeft',\n closeKey: 'ArrowRight',\n },\n ] as {\n dir: 'ltr' | 'rtl' | 'auto';\n openKey: 'ArrowRight' | 'ArrowLeft';\n closeKey: 'ArrowRight' | 'ArrowLeft';\n }[]\n ).map((testData) => {\n it(`selects - keyboard: ${testData.dir}`, async () => {\n const rootChanged = spy();\n const submenuChanged = spy();\n const el = await styledFixture<Menu>(\n html`\n <sp-menu\n @change=${(event: Event & { target: Menu }) => {\n rootChanged(event.target.value);\n }}\n >\n <sp-menu-item class=\"root\">\n Has submenu\n <sp-menu\n slot=\"submenu\"\n @change=${(event: Event & { target: Menu }) => {\n submenuChanged(event.target.value);\n }}\n >\n <sp-menu-item class=\"submenu-item-1\">\n One\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-2\">\n Two\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-3\">\n Three\n </sp-menu-item>\n </sp-menu>\n </sp-menu-item>\n </sp-menu>\n `,\n testData.dir\n );\n\n await elementUpdated(el);\n const rootItem = el.querySelector('.root') as MenuItem;\n expect(rootItem.open).to.be.false;\n el.focus();\n await elementUpdated(el);\n\n let opened = oneEvent(rootItem, 'sp-opened');\n sendKeys({\n press: testData.openKey,\n });\n await opened;\n\n expect(rootItem.open).to.be.true;\n\n let closed = oneEvent(rootItem, 'sp-closed');\n sendKeys({\n press: testData.closeKey,\n });\n await closed;\n\n expect(rootItem.open).to.be.false;\n\n opened = oneEvent(rootItem, 'sp-opened');\n sendKeys({\n press: testData.openKey,\n });\n await opened;\n\n expect(rootItem.open).to.be.true;\n\n await sendKeys({\n press: 'ArrowDown',\n });\n\n closed = oneEvent(rootItem, 'sp-closed');\n sendKeys({\n press: 'Enter',\n });\n await closed;\n\n expect(rootChanged.calledWith('Has submenu'), 'root changed').to.be\n .true;\n expect(submenuChanged.calledWith('Two'), 'submenu changed').to.be\n .true;\n });\n });\n it('closes on `pointerleave`', async () => {\n const el = await styledFixture<Menu>(\n html`\n <sp-menu>\n <sp-menu-item class=\"root\">\n Has submenu\n <sp-menu slot=\"submenu\">\n <sp-menu-item class=\"submenu-item-1\">\n One\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-2\">\n Two\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-3\">\n Three\n </sp-menu-item>\n </sp-menu>\n </sp-menu-item>\n </sp-menu>\n `\n );\n\n await elementUpdated(el);\n const rootItem = el.querySelector('.root') as MenuItem;\n const rootItemBoundingRect = rootItem.getBoundingClientRect();\n expect(rootItem.open).to.be.false;\n\n const opened = oneEvent(rootItem, 'sp-opened');\n sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height / 2,\n ],\n },\n ],\n });\n await opened;\n\n expect(rootItem.open).to.be.true;\n\n const closed = oneEvent(rootItem, 'sp-closed');\n sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height * 2,\n ],\n },\n ],\n });\n await closed;\n\n expect(rootItem.open).to.be.false;\n });\n it('stays open when mousing off menu item and back again', async () => {\n const el = await styledFixture<Menu>(\n html`\n <sp-menu>\n <sp-menu-item class=\"root\">\n Has submenu\n <sp-menu slot=\"submenu\">\n <sp-menu-item class=\"submenu-item-1\">\n One\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-2\">\n Two\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-3\">\n Three\n </sp-menu-item>\n </sp-menu>\n </sp-menu-item>\n </sp-menu>\n `\n );\n\n await elementUpdated(el);\n const rootItem = el.querySelector('.root') as MenuItem;\n const rootItemBoundingRect = rootItem.getBoundingClientRect();\n expect(rootItem.open).to.be.false;\n\n const opened = oneEvent(rootItem, 'sp-opened');\n await sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height / 2,\n ],\n },\n ],\n });\n await sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height * 2,\n ],\n },\n ],\n });\n await sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height / 2,\n ],\n },\n ],\n });\n await opened;\n\n expect(rootItem.open).to.be.true;\n\n const closed = oneEvent(rootItem, 'sp-closed');\n sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height * 2,\n ],\n },\n ],\n });\n await closed;\n });\n it('stays open when mousing between menu item and submenu', async () => {\n const el = await styledFixture<Menu>(\n html`\n <sp-menu>\n <sp-menu-item class=\"root\">\n Has submenu\n <sp-menu slot=\"submenu\">\n <sp-menu-item class=\"submenu-item-1\">\n One\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-2\">\n Two\n </sp-menu-item>\n <sp-menu-item class=\"submenu-item-3\">\n Three\n </sp-menu-item>\n </sp-menu>\n </sp-menu-item>\n </sp-menu>\n `\n );\n\n await elementUpdated(el);\n const rootItem = el.querySelector('.root') as MenuItem;\n const rootItemBoundingRect = rootItem.getBoundingClientRect();\n expect(rootItem.open).to.be.false;\n\n const opened = oneEvent(rootItem, 'sp-opened');\n await sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height / 2,\n ],\n },\n ],\n });\n await sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width / 2,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height * 2,\n ],\n },\n ],\n });\n await sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n rootItemBoundingRect.left +\n rootItemBoundingRect.width * 1.5,\n rootItemBoundingRect.top +\n rootItemBoundingRect.height / 2,\n ],\n },\n ],\n });\n await opened;\n\n expect(rootItem.open).to.be.true;\n });\n});\n"]}