@spectrum-web-components/menu 0.35.0 → 0.35.1-rc.24
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.
- package/package.json +9 -9
- package/src/Menu.d.ts +16 -6
- package/src/Menu.dev.js +162 -61
- package/src/Menu.dev.js.map +2 -2
- package/src/Menu.js +7 -3
- package/src/Menu.js.map +3 -3
- package/src/MenuGroup.d.ts +0 -2
- package/src/MenuGroup.dev.js +6 -10
- package/src/MenuGroup.dev.js.map +2 -2
- package/src/MenuGroup.js +3 -5
- package/src/MenuGroup.js.map +3 -3
- package/src/MenuItem.d.ts +26 -23
- package/src/MenuItem.dev.js +140 -185
- package/src/MenuItem.dev.js.map +3 -3
- package/src/MenuItem.js +35 -15
- package/src/MenuItem.js.map +3 -3
- package/src/menu-item.css.dev.js +1 -1
- package/src/menu-item.css.dev.js.map +1 -1
- package/src/menu-item.css.js +1 -1
- package/src/menu-item.css.js.map +1 -1
- package/src/menu.css.dev.js +1 -1
- package/src/menu.css.dev.js.map +1 -1
- package/src/menu.css.js +1 -1
- package/src/menu.css.js.map +1 -1
- package/stories/submenu.stories.js +107 -104
- package/stories/submenu.stories.js.map +3 -3
- package/test/menu-group.test.js +14 -1
- package/test/menu-group.test.js.map +2 -2
- package/test/menu-selects.test.js +3 -1
- package/test/menu-selects.test.js.map +2 -2
- package/test/menu.test.js +7 -0
- package/test/menu.test.js.map +2 -2
- package/test/submenu.test.js +206 -84
- package/test/submenu.test.js.map +2 -2
- package/custom-elements.json +0 -2252
package/test/submenu.test.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import "@spectrum-web-components/menu/sp-menu.js";
|
|
3
3
|
import "@spectrum-web-components/menu/sp-menu-item.js";
|
|
4
4
|
import {
|
|
5
|
+
aTimeout,
|
|
5
6
|
elementUpdated,
|
|
6
7
|
expect,
|
|
7
8
|
fixture,
|
|
@@ -19,7 +20,40 @@ import "@spectrum-web-components/menu/sp-menu-group.js";
|
|
|
19
20
|
import "@spectrum-web-components/icons-workflow/icons/sp-icon-show-menu.js";
|
|
20
21
|
async function styledFixture(story, dir = "ltr") {
|
|
21
22
|
const test = await fixture(html`
|
|
22
|
-
<sp-theme dir=${dir} scale="medium" color="dark"
|
|
23
|
+
<sp-theme dir=${dir} scale="medium" color="dark">
|
|
24
|
+
${story}
|
|
25
|
+
<style>
|
|
26
|
+
sp-theme {
|
|
27
|
+
--spectrum-global-animation-duration-100: 50ms;
|
|
28
|
+
--spectrum-global-animation-duration-200: 50ms;
|
|
29
|
+
--spectrum-global-animation-duration-300: 50ms;
|
|
30
|
+
--spectrum-global-animation-duration-400: 50ms;
|
|
31
|
+
--spectrum-global-animation-duration-500: 50ms;
|
|
32
|
+
--spectrum-global-animation-duration-600: 50ms;
|
|
33
|
+
--spectrum-global-animation-duration-700: 50ms;
|
|
34
|
+
--spectrum-global-animation-duration-800: 50ms;
|
|
35
|
+
--spectrum-global-animation-duration-900: 50ms;
|
|
36
|
+
--spectrum-global-animation-duration-1000: 50ms;
|
|
37
|
+
--spectrum-global-animation-duration-2000: 50ms;
|
|
38
|
+
--spectrum-global-animation-duration-4000: 50ms;
|
|
39
|
+
--spectrum-animation-duration-0: 50ms;
|
|
40
|
+
--spectrum-animation-duration-100: 50ms;
|
|
41
|
+
--spectrum-animation-duration-200: 50ms;
|
|
42
|
+
--spectrum-animation-duration-300: 50ms;
|
|
43
|
+
--spectrum-animation-duration-400: 50ms;
|
|
44
|
+
--spectrum-animation-duration-500: 50ms;
|
|
45
|
+
--spectrum-animation-duration-600: 50ms;
|
|
46
|
+
--spectrum-animation-duration-700: 50ms;
|
|
47
|
+
--spectrum-animation-duration-800: 50ms;
|
|
48
|
+
--spectrum-animation-duration-900: 50ms;
|
|
49
|
+
--spectrum-animation-duration-1000: 50ms;
|
|
50
|
+
--spectrum-animation-duration-2000: 50ms;
|
|
51
|
+
--spectrum-animation-duration-4000: 50ms;
|
|
52
|
+
--spectrum-coachmark-animation-indicator-ring-duration: 50ms;
|
|
53
|
+
--swc-test-duration: 1ms;
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
56
|
+
</sp-theme>
|
|
23
57
|
`);
|
|
24
58
|
document.documentElement.dir = dir;
|
|
25
59
|
return test.children[0];
|
|
@@ -90,9 +124,8 @@ describe("Submenu", () => {
|
|
|
90
124
|
]
|
|
91
125
|
});
|
|
92
126
|
await closed;
|
|
93
|
-
|
|
94
|
-
expect(rootChanged.
|
|
95
|
-
expect(submenuChanged.calledWith("Two"), "submenu changed").to.be.true;
|
|
127
|
+
expect(submenuChanged.withArgs("Two").calledOnce, "submenu changed").to.be.true;
|
|
128
|
+
expect(rootChanged.withArgs("Has submenu").calledOnce, "root changed").to.be.true;
|
|
96
129
|
});
|
|
97
130
|
it("closes deep tree on selection", async () => {
|
|
98
131
|
const rootChanged = spy();
|
|
@@ -143,11 +176,12 @@ describe("Submenu", () => {
|
|
|
143
176
|
</sp-menu>
|
|
144
177
|
`
|
|
145
178
|
);
|
|
146
|
-
await elementUpdated(el);
|
|
147
179
|
const rootItem = el.querySelector(".root");
|
|
148
180
|
const rootItemBoundingRect = rootItem.getBoundingClientRect();
|
|
181
|
+
const item2 = document.querySelector(".submenu-item-2");
|
|
182
|
+
const itemC = document.querySelector(".sub-submenu-item-3");
|
|
149
183
|
expect(rootItem.open).to.be.false;
|
|
150
|
-
|
|
184
|
+
let opened = oneEvent(rootItem, "sp-opened");
|
|
151
185
|
sendMouse({
|
|
152
186
|
steps: [
|
|
153
187
|
{
|
|
@@ -161,9 +195,8 @@ describe("Submenu", () => {
|
|
|
161
195
|
});
|
|
162
196
|
await opened;
|
|
163
197
|
expect(rootItem.open).to.be.true;
|
|
164
|
-
const item2 = document.querySelector(".submenu-item-2");
|
|
165
198
|
const item2BoundingRect = item2.getBoundingClientRect();
|
|
166
|
-
|
|
199
|
+
opened = oneEvent(item2, "sp-opened");
|
|
167
200
|
sendMouse({
|
|
168
201
|
steps: [
|
|
169
202
|
{
|
|
@@ -175,25 +208,11 @@ describe("Submenu", () => {
|
|
|
175
208
|
}
|
|
176
209
|
]
|
|
177
210
|
});
|
|
178
|
-
await
|
|
179
|
-
await nextFrame();
|
|
211
|
+
await opened;
|
|
180
212
|
expect(item2.open).to.be.true;
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
closed = oneEvent(rootItem, "sp-closed");
|
|
184
|
-
sendMouse({
|
|
185
|
-
steps: [
|
|
186
|
-
{
|
|
187
|
-
type: "click",
|
|
188
|
-
position: [
|
|
189
|
-
itemCBoundingRect.left + itemCBoundingRect.width / 2,
|
|
190
|
-
itemCBoundingRect.top + itemCBoundingRect.height / 2
|
|
191
|
-
]
|
|
192
|
-
}
|
|
193
|
-
]
|
|
194
|
-
});
|
|
213
|
+
const closed = oneEvent(rootItem, "sp-closed");
|
|
214
|
+
itemC.click();
|
|
195
215
|
await closed;
|
|
196
|
-
await nextFrame();
|
|
197
216
|
expect(rootChanged.calledWith("Has submenu"), "root changed").to.be.true;
|
|
198
217
|
expect(submenuChanged.calledWith("Two"), "submenu changed").to.be.true;
|
|
199
218
|
expect(subSubmenuChanged.calledWith("C"), "sub submenu changed").to.be.true;
|
|
@@ -210,12 +229,14 @@ describe("Submenu", () => {
|
|
|
210
229
|
closeKey: "ArrowRight"
|
|
211
230
|
}
|
|
212
231
|
].map((testData) => {
|
|
213
|
-
it(`selects - keyboard: ${testData.dir}`, async ()
|
|
232
|
+
it(`selects - keyboard: ${testData.dir}`, async function() {
|
|
233
|
+
var _a, _b;
|
|
214
234
|
const rootChanged = spy();
|
|
215
235
|
const submenuChanged = spy();
|
|
216
236
|
const el = await styledFixture(
|
|
217
237
|
html`
|
|
218
238
|
<sp-menu
|
|
239
|
+
id="base"
|
|
219
240
|
@change=${(event) => {
|
|
220
241
|
rootChanged(event.target.value);
|
|
221
242
|
}}
|
|
@@ -223,6 +244,7 @@ describe("Submenu", () => {
|
|
|
223
244
|
<sp-menu-item class="root">
|
|
224
245
|
Has submenu
|
|
225
246
|
<sp-menu
|
|
247
|
+
id="sub"
|
|
226
248
|
slot="submenu"
|
|
227
249
|
@change=${(event) => {
|
|
228
250
|
submenuChanged(event.target.value);
|
|
@@ -245,6 +267,8 @@ describe("Submenu", () => {
|
|
|
245
267
|
);
|
|
246
268
|
await elementUpdated(el);
|
|
247
269
|
const rootItem = el.querySelector(".root");
|
|
270
|
+
const submenu = el.querySelector('[slot="submenu"]');
|
|
271
|
+
const submenuItem = el.querySelector(".submenu-item-2");
|
|
248
272
|
expect(rootItem.open).to.be.false;
|
|
249
273
|
el.focus();
|
|
250
274
|
await elementUpdated(el);
|
|
@@ -254,12 +278,20 @@ describe("Submenu", () => {
|
|
|
254
278
|
});
|
|
255
279
|
await opened;
|
|
256
280
|
expect(rootItem.open).to.be.true;
|
|
281
|
+
expect(
|
|
282
|
+
submenu === document.activeElement,
|
|
283
|
+
`${(_a = document.activeElement) == null ? void 0 : _a.id}`
|
|
284
|
+
).to.be.true;
|
|
257
285
|
let closed = oneEvent(rootItem, "sp-closed");
|
|
258
286
|
sendKeys({
|
|
259
287
|
press: testData.closeKey
|
|
260
288
|
});
|
|
261
289
|
await closed;
|
|
262
290
|
expect(rootItem.open).to.be.false;
|
|
291
|
+
expect(
|
|
292
|
+
el === document.activeElement,
|
|
293
|
+
`${(_b = document.activeElement) == null ? void 0 : _b.id}`
|
|
294
|
+
).to.be.true;
|
|
263
295
|
opened = oneEvent(rootItem, "sp-opened");
|
|
264
296
|
sendKeys({
|
|
265
297
|
press: testData.openKey
|
|
@@ -269,13 +301,23 @@ describe("Submenu", () => {
|
|
|
269
301
|
await sendKeys({
|
|
270
302
|
press: "ArrowDown"
|
|
271
303
|
});
|
|
304
|
+
await elementUpdated(submenuItem);
|
|
305
|
+
await nextFrame();
|
|
306
|
+
await nextFrame();
|
|
307
|
+
expect(submenu.getAttribute("aria-activedescendant")).to.equal(
|
|
308
|
+
submenuItem.id
|
|
309
|
+
);
|
|
272
310
|
closed = oneEvent(rootItem, "sp-closed");
|
|
273
311
|
sendKeys({
|
|
274
312
|
press: "Enter"
|
|
275
313
|
});
|
|
276
314
|
await closed;
|
|
277
|
-
expect(rootChanged.calledWith("Has submenu"), "root changed").to.be.true;
|
|
278
315
|
expect(submenuChanged.calledWith("Two"), "submenu changed").to.be.true;
|
|
316
|
+
expect(rootChanged.called, "root has changed").to.be.true;
|
|
317
|
+
expect(
|
|
318
|
+
rootChanged.calledWith("Has submenu"),
|
|
319
|
+
"root specifically changed"
|
|
320
|
+
).to.be.true;
|
|
279
321
|
});
|
|
280
322
|
});
|
|
281
323
|
it("closes on `pointerleave`", async () => {
|
|
@@ -407,7 +449,8 @@ describe("Submenu", () => {
|
|
|
407
449
|
});
|
|
408
450
|
await closed;
|
|
409
451
|
});
|
|
410
|
-
it("
|
|
452
|
+
it("continues to open when mousing between menu item and submenu", async () => {
|
|
453
|
+
const clickSpy = spy();
|
|
411
454
|
const el = await styledFixture(
|
|
412
455
|
html`
|
|
413
456
|
<sp-menu>
|
|
@@ -417,7 +460,10 @@ describe("Submenu", () => {
|
|
|
417
460
|
<sp-menu-item class="submenu-item-1">
|
|
418
461
|
One
|
|
419
462
|
</sp-menu-item>
|
|
420
|
-
<sp-menu-item
|
|
463
|
+
<sp-menu-item
|
|
464
|
+
class="submenu-item-2"
|
|
465
|
+
@click=${() => clickSpy()}
|
|
466
|
+
>
|
|
421
467
|
Two
|
|
422
468
|
</sp-menu-item>
|
|
423
469
|
<sp-menu-item class="submenu-item-3">
|
|
@@ -430,6 +476,7 @@ describe("Submenu", () => {
|
|
|
430
476
|
);
|
|
431
477
|
await elementUpdated(el);
|
|
432
478
|
const rootItem = el.querySelector(".root");
|
|
479
|
+
const subItem = el.querySelector(".submenu-item-2");
|
|
433
480
|
const rootItemBoundingRect = rootItem.getBoundingClientRect();
|
|
434
481
|
expect(rootItem.open).to.be.false;
|
|
435
482
|
const opened = oneEvent(rootItem, "sp-opened");
|
|
@@ -444,30 +491,114 @@ describe("Submenu", () => {
|
|
|
444
491
|
}
|
|
445
492
|
]
|
|
446
493
|
});
|
|
494
|
+
await nextFrame();
|
|
495
|
+
await nextFrame();
|
|
496
|
+
const subItemBoundingRect = subItem.getBoundingClientRect();
|
|
447
497
|
await sendMouse({
|
|
448
498
|
steps: [
|
|
449
499
|
{
|
|
450
500
|
type: "move",
|
|
451
501
|
position: [
|
|
452
|
-
|
|
453
|
-
|
|
502
|
+
subItemBoundingRect.left + subItemBoundingRect.width / 2,
|
|
503
|
+
subItemBoundingRect.top + subItemBoundingRect.height / 2
|
|
454
504
|
]
|
|
455
505
|
}
|
|
456
506
|
]
|
|
457
507
|
});
|
|
508
|
+
await opened;
|
|
509
|
+
expect(rootItem.open).to.be.true;
|
|
510
|
+
await aTimeout(150);
|
|
511
|
+
expect(rootItem.open).to.be.true;
|
|
512
|
+
const closed = oneEvent(rootItem, "sp-closed");
|
|
513
|
+
sendMouse({
|
|
514
|
+
steps: [
|
|
515
|
+
{
|
|
516
|
+
type: "click",
|
|
517
|
+
position: [
|
|
518
|
+
subItemBoundingRect.left + subItemBoundingRect.width / 2,
|
|
519
|
+
subItemBoundingRect.top + subItemBoundingRect.height / 2
|
|
520
|
+
]
|
|
521
|
+
}
|
|
522
|
+
]
|
|
523
|
+
});
|
|
524
|
+
await closed;
|
|
525
|
+
expect(clickSpy.callCount).to.equal(1);
|
|
526
|
+
});
|
|
527
|
+
it("stays open when mousing between menu item and submenu", async () => {
|
|
528
|
+
const clickSpy = spy();
|
|
529
|
+
const el = await styledFixture(
|
|
530
|
+
html`
|
|
531
|
+
<sp-menu>
|
|
532
|
+
<sp-menu-item class="root">
|
|
533
|
+
Has submenu
|
|
534
|
+
<sp-menu slot="submenu">
|
|
535
|
+
<sp-menu-item class="submenu-item-1">
|
|
536
|
+
One
|
|
537
|
+
</sp-menu-item>
|
|
538
|
+
<sp-menu-item
|
|
539
|
+
class="submenu-item-2"
|
|
540
|
+
@click=${() => clickSpy()}
|
|
541
|
+
>
|
|
542
|
+
Two
|
|
543
|
+
</sp-menu-item>
|
|
544
|
+
<sp-menu-item class="submenu-item-3">
|
|
545
|
+
Three
|
|
546
|
+
</sp-menu-item>
|
|
547
|
+
</sp-menu>
|
|
548
|
+
</sp-menu-item>
|
|
549
|
+
</sp-menu>
|
|
550
|
+
`
|
|
551
|
+
);
|
|
552
|
+
await elementUpdated(el);
|
|
553
|
+
const rootItem = el.querySelector(".root");
|
|
554
|
+
const subItem = el.querySelector(".submenu-item-2");
|
|
555
|
+
const rootItemBoundingRect = rootItem.getBoundingClientRect();
|
|
556
|
+
expect(rootItem.open).to.be.false;
|
|
557
|
+
const opened = oneEvent(rootItem, "sp-opened");
|
|
458
558
|
await sendMouse({
|
|
459
559
|
steps: [
|
|
460
560
|
{
|
|
461
561
|
type: "move",
|
|
462
562
|
position: [
|
|
463
|
-
rootItemBoundingRect.left + rootItemBoundingRect.width
|
|
563
|
+
rootItemBoundingRect.left + rootItemBoundingRect.width / 2,
|
|
464
564
|
rootItemBoundingRect.top + rootItemBoundingRect.height / 2
|
|
465
565
|
]
|
|
466
566
|
}
|
|
467
567
|
]
|
|
468
568
|
});
|
|
469
569
|
await opened;
|
|
570
|
+
await nextFrame();
|
|
571
|
+
await nextFrame();
|
|
572
|
+
const subItemBoundingRect = subItem.getBoundingClientRect();
|
|
470
573
|
expect(rootItem.open).to.be.true;
|
|
574
|
+
await sendMouse({
|
|
575
|
+
steps: [
|
|
576
|
+
{
|
|
577
|
+
type: "move",
|
|
578
|
+
position: [
|
|
579
|
+
subItemBoundingRect.left + subItemBoundingRect.width / 2,
|
|
580
|
+
subItemBoundingRect.top + subItemBoundingRect.height / 2
|
|
581
|
+
]
|
|
582
|
+
}
|
|
583
|
+
]
|
|
584
|
+
});
|
|
585
|
+
expect(rootItem.open).to.be.true;
|
|
586
|
+
await aTimeout(150);
|
|
587
|
+
expect(rootItem.open).to.be.true;
|
|
588
|
+
const closed = oneEvent(rootItem, "sp-closed");
|
|
589
|
+
sendMouse({
|
|
590
|
+
steps: [
|
|
591
|
+
{
|
|
592
|
+
type: "click",
|
|
593
|
+
position: [
|
|
594
|
+
subItemBoundingRect.left + subItemBoundingRect.width / 2,
|
|
595
|
+
subItemBoundingRect.top + subItemBoundingRect.height / 2
|
|
596
|
+
]
|
|
597
|
+
}
|
|
598
|
+
]
|
|
599
|
+
});
|
|
600
|
+
await closed;
|
|
601
|
+
expect(clickSpy.callCount).to.equal(1);
|
|
471
602
|
});
|
|
472
603
|
it("not opens if disabled", async () => {
|
|
473
604
|
const el = await styledFixture(
|
|
@@ -512,15 +643,15 @@ describe("Submenu", () => {
|
|
|
512
643
|
const el = await styledFixture(html`
|
|
513
644
|
<sp-action-menu>
|
|
514
645
|
<sp-icon-show-menu slot="icon"></sp-icon-show-menu>
|
|
515
|
-
<sp-menu-group role="none">
|
|
646
|
+
<sp-menu-group role="none" id="group">
|
|
516
647
|
<span slot="header">New York</span>
|
|
517
648
|
<sp-menu-item>Bronx</sp-menu-item>
|
|
518
649
|
<sp-menu-item id="submenu-item-1">
|
|
519
650
|
Brooklyn
|
|
520
|
-
<sp-menu slot="submenu">
|
|
651
|
+
<sp-menu slot="submenu" id="submenu-1">
|
|
521
652
|
<sp-menu-item id="submenu-item-2">
|
|
522
653
|
Ft. Greene
|
|
523
|
-
<sp-menu slot="submenu">
|
|
654
|
+
<sp-menu slot="submenu" id="submenu-2">
|
|
524
655
|
<sp-menu-item>S. Oxford St</sp-menu-item>
|
|
525
656
|
<sp-menu-item>S. Portland Ave</sp-menu-item>
|
|
526
657
|
<sp-menu-item>S. Elliot Pl</sp-menu-item>
|
|
@@ -532,7 +663,7 @@ describe("Submenu", () => {
|
|
|
532
663
|
</sp-menu-item>
|
|
533
664
|
<sp-menu-item id="submenu-item-3">
|
|
534
665
|
Manhattan
|
|
535
|
-
<sp-menu slot="submenu">
|
|
666
|
+
<sp-menu slot="submenu" id="submenu-3">
|
|
536
667
|
<sp-menu-item disabled>SoHo</sp-menu-item>
|
|
537
668
|
<sp-menu-item>
|
|
538
669
|
Union Square
|
|
@@ -556,33 +687,27 @@ describe("Submenu", () => {
|
|
|
556
687
|
el.click();
|
|
557
688
|
await opened;
|
|
558
689
|
expect(el.open).to.be.true;
|
|
559
|
-
let activeOverlays = document.querySelectorAll("active-overlay");
|
|
560
|
-
expect(activeOverlays.length).to.equal(1);
|
|
561
690
|
opened = oneEvent(rootMenu1, "sp-opened");
|
|
562
691
|
rootMenu1.dispatchEvent(
|
|
563
692
|
new PointerEvent("pointerenter", { bubbles: true })
|
|
564
693
|
);
|
|
565
694
|
await opened;
|
|
566
|
-
|
|
567
|
-
expect(activeOverlays.length).to.equal(2);
|
|
695
|
+
expect(rootMenu1.open).to.be.true;
|
|
568
696
|
opened = oneEvent(childMenu2, "sp-opened");
|
|
569
697
|
childMenu2.dispatchEvent(
|
|
570
698
|
new PointerEvent("pointerenter", { bubbles: true })
|
|
571
699
|
);
|
|
572
700
|
await opened;
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
oneEvent(rootMenu1, "sp-closed"),
|
|
578
|
-
oneEvent(rootMenu2, "sp-opened")
|
|
579
|
-
]);
|
|
701
|
+
expect(childMenu2.open).to.be.true;
|
|
702
|
+
const childMenu2Closed = oneEvent(childMenu2, "sp-closed");
|
|
703
|
+
const rootMenu1Closed = oneEvent(rootMenu1, "sp-closed");
|
|
704
|
+
const rootMenu2Opened = oneEvent(rootMenu2, "sp-opened");
|
|
580
705
|
rootMenu2.dispatchEvent(
|
|
581
706
|
new PointerEvent("pointerenter", { bubbles: true })
|
|
582
707
|
);
|
|
583
|
-
await
|
|
584
|
-
|
|
585
|
-
|
|
708
|
+
await childMenu2Closed;
|
|
709
|
+
await rootMenu1Closed;
|
|
710
|
+
await rootMenu2Opened;
|
|
586
711
|
});
|
|
587
712
|
it("closes back to the first overlay without a `root` when clicking away", async () => {
|
|
588
713
|
const el = await styledFixture(html`
|
|
@@ -631,31 +756,30 @@ describe("Submenu", () => {
|
|
|
631
756
|
el.click();
|
|
632
757
|
await opened;
|
|
633
758
|
expect(el.open).to.be.true;
|
|
634
|
-
let activeOverlays = document.querySelectorAll("active-overlay");
|
|
635
|
-
expect(activeOverlays.length).to.equal(1);
|
|
636
759
|
opened = oneEvent(rootMenu1, "sp-opened");
|
|
637
760
|
rootMenu1.dispatchEvent(
|
|
638
761
|
new PointerEvent("pointerenter", { bubbles: true })
|
|
639
762
|
);
|
|
640
763
|
await opened;
|
|
641
|
-
activeOverlays = document.querySelectorAll("active-overlay");
|
|
642
|
-
expect(activeOverlays.length).to.equal(2);
|
|
643
764
|
opened = oneEvent(childMenu2, "sp-opened");
|
|
644
765
|
childMenu2.dispatchEvent(
|
|
645
766
|
new PointerEvent("pointerenter", { bubbles: true })
|
|
646
767
|
);
|
|
647
768
|
await opened;
|
|
648
|
-
activeOverlays = document.querySelectorAll("active-overlay");
|
|
649
|
-
expect(activeOverlays.length).to.equal(3);
|
|
650
769
|
const closed = Promise.all([
|
|
651
770
|
oneEvent(childMenu2, "sp-closed"),
|
|
652
771
|
oneEvent(rootMenu1, "sp-closed"),
|
|
653
772
|
oneEvent(el, "sp-closed")
|
|
654
773
|
]);
|
|
655
|
-
|
|
774
|
+
sendMouse({
|
|
775
|
+
steps: [
|
|
776
|
+
{
|
|
777
|
+
type: "click",
|
|
778
|
+
position: [600, 5]
|
|
779
|
+
}
|
|
780
|
+
]
|
|
781
|
+
});
|
|
656
782
|
await closed;
|
|
657
|
-
activeOverlays = document.querySelectorAll("active-overlay");
|
|
658
|
-
expect(activeOverlays.length).to.equal(0);
|
|
659
783
|
});
|
|
660
784
|
it("closes decendent menus when Menu Item in ancestor without a submenu is pointerentered", async () => {
|
|
661
785
|
const el = await styledFixture(html`
|
|
@@ -694,22 +818,16 @@ describe("Submenu", () => {
|
|
|
694
818
|
el.click();
|
|
695
819
|
await opened;
|
|
696
820
|
expect(el.open).to.be.true;
|
|
697
|
-
let activeOverlays = document.querySelectorAll("active-overlay");
|
|
698
|
-
expect(activeOverlays.length).to.equal(1);
|
|
699
821
|
opened = oneEvent(rootMenu, "sp-opened");
|
|
700
822
|
rootMenu.dispatchEvent(
|
|
701
823
|
new PointerEvent("pointerenter", { bubbles: true })
|
|
702
824
|
);
|
|
703
825
|
await opened;
|
|
704
|
-
activeOverlays = document.querySelectorAll("active-overlay");
|
|
705
|
-
expect(activeOverlays.length).to.equal(2);
|
|
706
826
|
const closed = oneEvent(rootMenu, "sp-closed");
|
|
707
827
|
noSubmenu.dispatchEvent(
|
|
708
828
|
new PointerEvent("pointerenter", { bubbles: true })
|
|
709
829
|
);
|
|
710
830
|
await closed;
|
|
711
|
-
activeOverlays = document.querySelectorAll("active-overlay");
|
|
712
|
-
expect(activeOverlays.length).to.equal(1);
|
|
713
831
|
});
|
|
714
832
|
it("closes decendent menus when Menu Item in ancestor is clicked", async () => {
|
|
715
833
|
const el = await styledFixture(html`
|
|
@@ -753,6 +871,7 @@ describe("Submenu", () => {
|
|
|
753
871
|
</sp-menu-group>
|
|
754
872
|
</sp-action-menu>
|
|
755
873
|
`);
|
|
874
|
+
await nextFrame();
|
|
756
875
|
const rootMenu1 = el.querySelector("#submenu-item-1");
|
|
757
876
|
const childMenu2 = el.querySelector("#submenu-item-2");
|
|
758
877
|
const ancestorItem = el.querySelector("#ancestor-item");
|
|
@@ -761,33 +880,39 @@ describe("Submenu", () => {
|
|
|
761
880
|
el.click();
|
|
762
881
|
await opened;
|
|
763
882
|
expect(el.open).to.be.true;
|
|
764
|
-
let activeOverlays = document.querySelectorAll("active-overlay");
|
|
765
|
-
expect(activeOverlays.length).to.equal(1);
|
|
766
883
|
opened = oneEvent(rootMenu1, "sp-opened");
|
|
767
884
|
rootMenu1.dispatchEvent(
|
|
768
885
|
new PointerEvent("pointerenter", { bubbles: true })
|
|
769
886
|
);
|
|
770
887
|
await opened;
|
|
771
|
-
activeOverlays = document.querySelectorAll("active-overlay");
|
|
772
|
-
expect(activeOverlays.length).to.equal(2);
|
|
773
888
|
opened = oneEvent(childMenu2, "sp-opened");
|
|
774
889
|
childMenu2.dispatchEvent(
|
|
775
890
|
new PointerEvent("pointerenter", { bubbles: true })
|
|
776
891
|
);
|
|
777
892
|
await opened;
|
|
778
|
-
activeOverlays = document.querySelectorAll("active-overlay");
|
|
779
|
-
expect(activeOverlays.length).to.equal(3);
|
|
780
893
|
const closed = Promise.all([
|
|
781
894
|
oneEvent(childMenu2, "sp-closed"),
|
|
782
895
|
oneEvent(rootMenu1, "sp-closed"),
|
|
783
896
|
oneEvent(el, "sp-closed")
|
|
784
897
|
]);
|
|
785
|
-
ancestorItem.
|
|
898
|
+
const rect = ancestorItem.getBoundingClientRect();
|
|
899
|
+
await sendMouse({
|
|
900
|
+
steps: [
|
|
901
|
+
{
|
|
902
|
+
type: "click",
|
|
903
|
+
position: [
|
|
904
|
+
rect.left + rect.width / 2,
|
|
905
|
+
rect.top + rect.height / 2
|
|
906
|
+
]
|
|
907
|
+
}
|
|
908
|
+
]
|
|
909
|
+
});
|
|
786
910
|
await closed;
|
|
787
|
-
activeOverlays = document.querySelectorAll("active-overlay");
|
|
788
|
-
expect(activeOverlays.length).to.equal(0);
|
|
789
911
|
});
|
|
790
912
|
it('cleans up submenus that close before they are "open"', async () => {
|
|
913
|
+
if ("showPopover" in document.createElement("div")) {
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
791
916
|
await sendMouse({
|
|
792
917
|
steps: [
|
|
793
918
|
{
|
|
@@ -837,7 +962,6 @@ describe("Submenu", () => {
|
|
|
837
962
|
expect(rootItem2.open, "initially closed 2").to.be.false;
|
|
838
963
|
const rootItemBoundingRect1 = rootItem1.getBoundingClientRect();
|
|
839
964
|
const rootItemBoundingRect2 = rootItem2.getBoundingClientRect();
|
|
840
|
-
let activeOverlay;
|
|
841
965
|
await sendMouse({
|
|
842
966
|
steps: [
|
|
843
967
|
{
|
|
@@ -882,6 +1006,12 @@ describe("Submenu", () => {
|
|
|
882
1006
|
}
|
|
883
1007
|
]
|
|
884
1008
|
});
|
|
1009
|
+
await nextFrame();
|
|
1010
|
+
await nextFrame();
|
|
1011
|
+
await nextFrame();
|
|
1012
|
+
await nextFrame();
|
|
1013
|
+
await nextFrame();
|
|
1014
|
+
await nextFrame();
|
|
885
1015
|
const closed = oneEvent(rootItem2, "sp-closed");
|
|
886
1016
|
await sendMouse({
|
|
887
1017
|
steps: [
|
|
@@ -889,20 +1019,12 @@ describe("Submenu", () => {
|
|
|
889
1019
|
type: "move",
|
|
890
1020
|
position: [
|
|
891
1021
|
rootItemBoundingRect2.left + rootItemBoundingRect2.width / 2,
|
|
892
|
-
rootItemBoundingRect2.top + rootItemBoundingRect2.
|
|
1022
|
+
rootItemBoundingRect2.top + rootItemBoundingRect2.height * 2
|
|
893
1023
|
]
|
|
894
1024
|
}
|
|
895
1025
|
]
|
|
896
1026
|
});
|
|
897
|
-
activeOverlay = document.querySelector(
|
|
898
|
-
"active-overlay"
|
|
899
|
-
);
|
|
900
|
-
expect(activeOverlay).to.not.be.null;
|
|
901
1027
|
await closed;
|
|
902
|
-
activeOverlay = document.querySelector(
|
|
903
|
-
"active-overlay"
|
|
904
|
-
);
|
|
905
|
-
expect(activeOverlay).to.be.null;
|
|
906
1028
|
expect(rootItem1.open, "finally closed 1").to.be.false;
|
|
907
1029
|
expect(rootItem2.open, "finally closed 2").to.be.false;
|
|
908
1030
|
});
|