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