@@ -242,6 +242,7 @@ describe('items', () => {
242
242
it ( 'should not have a checked item' , async ( ) => {
243
243
rootMenu . items [ 0 ] . children [ 0 ] . checked = false ;
244
244
subMenu . close ( ) ;
245
+ await nextRender ( ) ;
245
246
await openMenu ( getMenuItems ( rootMenu ) [ 0 ] ) ;
246
247
expect ( getMenuItems ( subMenu ) [ 0 ] . hasAttribute ( 'menu-item-checked' ) ) . to . be . false ;
247
248
} ) ;
@@ -250,6 +251,27 @@ describe('items', () => {
250
251
expect ( getMenuItems ( subMenu ) [ 1 ] . disabled ) . to . be . true ;
251
252
} ) ;
252
253
254
+ it ( 'should update the submenu when activating other parent item' , ( ) => {
255
+ activateItem ( getMenuItems ( rootMenu ) [ 3 ] ) ;
256
+
257
+ expect ( subMenu . opened ) . to . be . true ;
258
+
259
+ const items = getMenuItems ( subMenu ) ;
260
+ expect ( items . length ) . to . equal ( 3 ) ;
261
+ expect ( items [ 0 ] . textContent ) . to . equal ( 'foo-3-0' ) ;
262
+ expect ( items [ 1 ] . textContent ) . to . equal ( 'foo-3-1' ) ;
263
+ expect ( items [ 2 ] . textContent ) . to . equal ( 'foo-3-2' ) ;
264
+ } ) ;
265
+
266
+ it ( 'should not change opened state of the submenu when activating other parent item' , ( ) => {
267
+ const openedChangeSpy = sinon . spy ( ) ;
268
+ subMenu . addEventListener ( 'opened-changed' , openedChangeSpy ) ;
269
+
270
+ activateItem ( getMenuItems ( rootMenu ) [ 3 ] ) ;
271
+
272
+ expect ( openedChangeSpy . called ) . to . be . false ;
273
+ } ) ;
274
+
253
275
it ( 'should close the submenu on activating non-parent item' , ( ) => {
254
276
activateItem ( getMenuItems ( rootMenu ) [ 1 ] ) ;
255
277
expect ( subMenu . opened ) . to . be . false ;
@@ -349,8 +371,9 @@ describe('items', () => {
349
371
expect ( getMenuItems ( rootMenu ) [ 0 ] . getAttribute ( 'aria-haspopup' ) ) . to . equal ( 'false' ) ;
350
372
} ) ;
351
373
352
- it ( 'should open item on right arrow' , ( ) => {
374
+ it ( 'should open item on right arrow' , async ( ) => {
353
375
subMenu . close ( ) ;
376
+ await nextRender ( ) ;
354
377
arrowRightKeyDown ( getMenuItems ( rootMenu ) [ 0 ] ) ;
355
378
expect ( subMenu . opened ) . to . be . true ;
356
379
} ) ;
@@ -359,25 +382,29 @@ describe('items', () => {
359
382
document . documentElement . setAttribute ( 'dir' , 'rtl' ) ;
360
383
await nextFrame ( ) ;
361
384
subMenu . close ( ) ;
385
+ await nextRender ( ) ;
362
386
arrowLeftKeyDown ( getMenuItems ( rootMenu ) [ 0 ] ) ;
363
387
expect ( subMenu . opened ) . to . be . true ;
364
388
document . documentElement . setAttribute ( 'dir' , 'ltr' ) ;
365
389
} ) ;
366
390
367
- it ( 'should open item on enter' , ( ) => {
391
+ it ( 'should open item on enter' , async ( ) => {
368
392
subMenu . close ( ) ;
393
+ await nextRender ( ) ;
369
394
enterKeyDown ( getMenuItems ( rootMenu ) [ 0 ] ) ;
370
395
expect ( subMenu . opened ) . to . be . true ;
371
396
} ) ;
372
397
373
- it ( 'should open item on space' , ( ) => {
398
+ it ( 'should open item on space' , async ( ) => {
374
399
subMenu . close ( ) ;
400
+ await nextRender ( ) ;
375
401
spaceKeyDown ( getMenuItems ( rootMenu ) [ 0 ] ) ;
376
402
expect ( subMenu . opened ) . to . be . true ;
377
403
} ) ;
378
404
379
405
it ( 'should not focus item if parent item is not focused' , async ( ) => {
380
406
subMenu . close ( ) ;
407
+ await nextRender ( ) ;
381
408
rootOverlay . focus ( ) ;
382
409
await openMenu ( getMenuItems ( rootMenu ) [ 0 ] ) ;
383
410
expect ( subMenu . opened ) . to . be . true ;
@@ -387,6 +414,7 @@ describe('items', () => {
387
414
388
415
it ( 'should focus first item in submenu on overlay element arrow down' , async ( ) => {
389
416
subMenu . close ( ) ;
417
+ await nextRender ( ) ;
390
418
rootOverlay . focus ( ) ;
391
419
await openMenu ( getMenuItems ( rootMenu ) [ 0 ] ) ;
392
420
const item = getMenuItems ( subMenu ) [ 0 ] ;
@@ -397,6 +425,7 @@ describe('items', () => {
397
425
398
426
it ( 'should focus last item in submenu on overlay element arrow up' , async ( ) => {
399
427
subMenu . close ( ) ;
428
+ await nextRender ( ) ;
400
429
rootOverlay . focus ( ) ;
401
430
await openMenu ( getMenuItems ( rootMenu ) [ 0 ] ) ;
402
431
const items = getMenuItems ( subMenu ) ;
@@ -408,6 +437,7 @@ describe('items', () => {
408
437
409
438
it ( 'should focus first item after re-opening when using components' , async ( ) => {
410
439
subMenu . close ( ) ;
440
+ await nextRender ( ) ;
411
441
rootOverlay . focus ( ) ;
412
442
413
443
const rootItem = getMenuItems ( rootMenu ) [ 3 ] ;
@@ -434,6 +464,7 @@ describe('items', () => {
434
464
435
465
it ( 'should focus first non-disabled item after re-opening when using components' , async ( ) => {
436
466
subMenu . close ( ) ;
467
+ await nextRender ( ) ;
437
468
rootOverlay . focus ( ) ;
438
469
439
470
rootMenu . items [ 3 ] . children [ 0 ] . disabled = true ;
@@ -529,6 +560,23 @@ describe('items', () => {
529
560
expect ( getMenuItems ( rootMenu ) [ 0 ] . getAttribute ( 'aria-expanded' ) ) . to . equal ( 'false' ) ;
530
561
} ) ;
531
562
563
+ it ( 'should update expanded attributes when activating different parent items' , async ( ) => {
564
+ expect ( getMenuItems ( rootMenu ) [ 0 ] . hasAttribute ( 'expanded' ) ) . to . be . true ;
565
+ expect ( getMenuItems ( rootMenu ) [ 0 ] . getAttribute ( 'aria-expanded' ) ) . to . equal ( 'true' ) ;
566
+
567
+ await activateItem ( getMenuItems ( rootMenu ) [ 3 ] ) ;
568
+ expect ( getMenuItems ( rootMenu ) [ 0 ] . hasAttribute ( 'expanded' ) ) . to . be . false ;
569
+ expect ( getMenuItems ( rootMenu ) [ 0 ] . getAttribute ( 'aria-expanded' ) ) . to . equal ( 'false' ) ;
570
+ expect ( getMenuItems ( rootMenu ) [ 3 ] . hasAttribute ( 'expanded' ) ) . to . be . true ;
571
+ expect ( getMenuItems ( rootMenu ) [ 3 ] . getAttribute ( 'aria-expanded' ) ) . to . equal ( 'true' ) ;
572
+
573
+ await activateItem ( getMenuItems ( rootMenu ) [ 0 ] ) ;
574
+ expect ( getMenuItems ( rootMenu ) [ 0 ] . hasAttribute ( 'expanded' ) ) . to . be . true ;
575
+ expect ( getMenuItems ( rootMenu ) [ 0 ] . getAttribute ( 'aria-expanded' ) ) . to . equal ( 'true' ) ;
576
+ expect ( getMenuItems ( rootMenu ) [ 3 ] . hasAttribute ( 'expanded' ) ) . to . be . false ;
577
+ expect ( getMenuItems ( rootMenu ) [ 3 ] . getAttribute ( 'aria-expanded' ) ) . to . equal ( 'false' ) ;
578
+ } ) ;
579
+
532
580
( isTouch ? describe . skip : describe ) ( 'scrolling' , ( ) => {
533
581
let rootOverlay , subOverlay1 , subOverlay2 , scrollElm ;
534
582
0 commit comments