@@ -35,7 +35,7 @@ describe('uib-dropdown', function() {
35
35
36
36
describe ( 'basic' , function ( ) {
37
37
function dropdown ( ) {
38
- return $compile ( '<li uib-dropdown><a href uib-dropdown-toggle></a><ul><li><a href>Hello</a></li></ul></li>' ) ( $rootScope ) ;
38
+ return $compile ( '<li uib-dropdown><a href uib-dropdown-toggle></a><ul uib-dropdown-menu ><li><a href>Hello</a></li></ul></li>' ) ( $rootScope ) ;
39
39
}
40
40
41
41
beforeEach ( function ( ) {
@@ -69,9 +69,10 @@ describe('uib-dropdown', function() {
69
69
} ) ;
70
70
71
71
it ( 'should close on escape key & focus toggle element' , function ( ) {
72
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
72
73
$document . find ( 'body' ) . append ( element ) ;
73
74
clickDropdownToggle ( ) ;
74
- var event = triggerKeyDown ( element , 27 ) ;
75
+ var event = triggerKeyDown ( dropdownMenu , 27 ) ;
75
76
expect ( element ) . not . toHaveClass ( dropdownConfig . openClass ) ;
76
77
expect ( element . find ( 'a' ) ) . toHaveFocus ( ) ;
77
78
expect ( event . stopPropagation ) . toHaveBeenCalled ( ) ;
@@ -108,7 +109,7 @@ describe('uib-dropdown', function() {
108
109
} ) ;
109
110
110
111
it ( 'should not toggle if the element has `disabled` class' , function ( ) {
111
- var elm = $compile ( '<li uib-dropdown><a class="disabled" uib-dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
112
+ var elm = $compile ( '<li uib-dropdown><a class="disabled" uib-dropdown-toggle></a><ul uib-dropdown-menu ><li>Hello</li></ul></li>' ) ( $rootScope ) ;
112
113
clickDropdownToggle ( elm ) ;
113
114
expect ( elm ) . not . toHaveClass ( dropdownConfig . openClass ) ;
114
115
} ) ;
@@ -121,7 +122,7 @@ describe('uib-dropdown', function() {
121
122
122
123
it ( 'should not toggle if the element has `ng-disabled` as true' , function ( ) {
123
124
$rootScope . isdisabled = true ;
124
- var elm = $compile ( '<li uib-dropdown><div ng-disabled="isdisabled" uib-dropdown-toggle></div><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
125
+ var elm = $compile ( '<li uib-dropdown><div ng-disabled="isdisabled" uib-dropdown-toggle></div><ul uib-dropdown-menu ><li>Hello</li></ul></li>' ) ( $rootScope ) ;
125
126
$rootScope . $digest ( ) ;
126
127
elm . find ( 'div' ) . click ( ) ;
127
128
expect ( elm ) . not . toHaveClass ( dropdownConfig . openClass ) ;
@@ -134,7 +135,7 @@ describe('uib-dropdown', function() {
134
135
135
136
it ( 'should unbind events on scope destroy' , function ( ) {
136
137
var $scope = $rootScope . $new ( ) ;
137
- var elm = $compile ( '<li uib-dropdown><button ng-disabled="isdisabled" uib-dropdown-toggle></button><ul><li>Hello</li></ul></li>' ) ( $scope ) ;
138
+ var elm = $compile ( '<li uib-dropdown><button ng-disabled="isdisabled" uib-dropdown-toggle></button><ul uib-dropdown-menu ><li>Hello</li></ul></li>' ) ( $scope ) ;
138
139
$scope . $digest ( ) ;
139
140
140
141
var buttonEl = elm . find ( 'button' ) ;
@@ -306,7 +307,7 @@ describe('uib-dropdown', function() {
306
307
describe ( 'with uib-dropdown-toggle' , function ( ) {
307
308
beforeEach ( function ( ) {
308
309
$rootScope . isopen = true ;
309
- element = $compile ( '<li uib-dropdown is-open="isopen"><a href uib-dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
310
+ element = $compile ( '<li uib-dropdown is-open="isopen"><a href uib-dropdown-toggle></a><ul uib-dropdown-menu ><li>Hello</li></ul></li>' ) ( $rootScope ) ;
310
311
$rootScope . $digest ( ) ;
311
312
} ) ;
312
313
@@ -340,7 +341,7 @@ describe('uib-dropdown', function() {
340
341
describe ( 'without uib-dropdown-toggle' , function ( ) {
341
342
beforeEach ( function ( ) {
342
343
$rootScope . isopen = true ;
343
- element = $compile ( '<li uib-dropdown is-open="isopen"><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
344
+ element = $compile ( '<li uib-dropdown is-open="isopen"><ul uib-dropdown-menu ><li>Hello</li></ul></li>' ) ( $rootScope ) ;
344
345
$rootScope . $digest ( ) ;
345
346
} ) ;
346
347
@@ -361,7 +362,7 @@ describe('uib-dropdown', function() {
361
362
beforeEach ( function ( ) {
362
363
$rootScope . toggleHandler = jasmine . createSpy ( 'toggleHandler' ) ;
363
364
$rootScope . isopen = false ;
364
- element = $compile ( '<li uib-dropdown on-toggle="toggleHandler(open)" is-open="isopen"><a uib-dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
365
+ element = $compile ( '<li uib-dropdown on-toggle="toggleHandler(open)" is-open="isopen"><a uib-dropdown-toggle></a><ul uib-dropdown-menu ><li>Hello</li></ul></li>' ) ( $rootScope ) ;
365
366
$rootScope . $digest ( ) ;
366
367
} ) ;
367
368
@@ -388,7 +389,7 @@ describe('uib-dropdown', function() {
388
389
beforeEach ( function ( ) {
389
390
$rootScope . toggleHandler = jasmine . createSpy ( 'toggleHandler' ) ;
390
391
$rootScope . isopen = true ;
391
- element = $compile ( '<li uib-dropdown on-toggle="toggleHandler(open)" is-open="isopen"><a uib-dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
392
+ element = $compile ( '<li uib-dropdown on-toggle="toggleHandler(open)" is-open="isopen"><a uib-dropdown-toggle></a><ul uib-dropdown-menu ><li>Hello</li></ul></li>' ) ( $rootScope ) ;
392
393
$rootScope . $digest ( ) ;
393
394
} ) ;
394
395
@@ -416,7 +417,7 @@ describe('uib-dropdown', function() {
416
417
describe ( 'without is-open' , function ( ) {
417
418
beforeEach ( function ( ) {
418
419
$rootScope . toggleHandler = jasmine . createSpy ( 'toggleHandler' ) ;
419
- element = $compile ( '<li uib-dropdown on-toggle="toggleHandler(open)"><a uib-dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
420
+ element = $compile ( '<li uib-dropdown on-toggle="toggleHandler(open)"><a uib-dropdown-toggle></a><ul uib-dropdown-menu ><li>Hello</li></ul></li>' ) ( $rootScope ) ;
420
421
$rootScope . $digest ( ) ;
421
422
} ) ;
422
423
@@ -444,7 +445,7 @@ describe('uib-dropdown', function() {
444
445
function dropdown ( autoClose ) {
445
446
return $compile ( '<li uib-dropdown ' +
446
447
( autoClose === undefined ? '' : 'auto-close="' + autoClose + '"' ) +
447
- '><a href uib-dropdown-toggle></a><ul><li><a href>Hello</a></li></ul></li>' ) ( $rootScope ) ;
448
+ '><a href uib-dropdown-toggle></a><ul uib-dropdown-menu ><li><a href>Hello</a></li></ul></li>' ) ( $rootScope ) ;
448
449
}
449
450
450
451
describe ( 'always' , function ( ) {
@@ -476,7 +477,7 @@ describe('uib-dropdown', function() {
476
477
477
478
it ( 'control with is-open' , function ( ) {
478
479
$rootScope . isopen = true ;
479
- element = $compile ( '<li uib-dropdown is-open="isopen" auto-close="disabled"><a href uib-dropdown-toggle></a><ul><li>Hello</li></ul></li>' ) ( $rootScope ) ;
480
+ element = $compile ( '<li uib-dropdown is-open="isopen" auto-close="disabled"><a href uib-dropdown-toggle></a><ul uib-dropdown-menu ><li>Hello</li></ul></li>' ) ( $rootScope ) ;
480
481
$rootScope . $digest ( ) ;
481
482
482
483
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
@@ -499,9 +500,10 @@ describe('uib-dropdown', function() {
499
500
500
501
it ( 'should close anyway if esc is pressed' , function ( ) {
501
502
element = dropdown ( 'disabled' ) ;
503
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
502
504
$document . find ( 'body' ) . append ( element ) ;
503
505
clickDropdownToggle ( ) ;
504
- triggerKeyDown ( element , 27 ) ;
506
+ triggerKeyDown ( dropdownMenu , 27 ) ;
505
507
expect ( element ) . not . toHaveClass ( dropdownConfig . openClass ) ;
506
508
expect ( element . find ( 'a' ) ) . toHaveFocus ( ) ;
507
509
} ) ;
@@ -546,66 +548,72 @@ describe('uib-dropdown', function() {
546
548
547
549
describe ( 'using keyboard-nav' , function ( ) {
548
550
function dropdown ( ) {
549
- return $compile ( '<li uib-dropdown keyboard-nav><a href uib-dropdown-toggle></a><ul><li><a href>Hello</a></li><li><a href>Hello Again</a></li></ul></li>' ) ( $rootScope ) ;
551
+ return $compile ( '<li uib-dropdown keyboard-nav><a href uib-dropdown-toggle></a><ul uib-dropdown-menu ><li><a href>Hello</a></li><li><a href>Hello Again</a></li></ul></li>' ) ( $rootScope ) ;
550
552
}
551
553
beforeEach ( function ( ) {
552
554
element = dropdown ( ) ;
553
555
} ) ;
554
556
555
557
it ( 'should focus first list element when down arrow pressed' , function ( ) {
558
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
556
559
$document . find ( 'body' ) . append ( element ) ;
557
560
clickDropdownToggle ( ) ;
558
- triggerKeyDown ( element , 40 ) ;
561
+ triggerKeyDown ( dropdownMenu , 40 ) ;
559
562
560
563
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
561
564
var optionEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
562
565
expect ( optionEl ) . toHaveFocus ( ) ;
563
566
} ) ;
564
567
565
568
it ( 'should not focus first list element when down arrow pressed if closed' , function ( ) {
569
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
566
570
$document . find ( 'body' ) . append ( element ) ;
567
- triggerKeyDown ( element , 40 ) ;
571
+ triggerKeyDown ( dropdownMenu , 40 ) ;
568
572
569
573
expect ( element ) . not . toHaveClass ( dropdownConfig . openClass ) ;
570
574
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
571
575
expect ( focusEl ) . not . toHaveFocus ( ) ;
572
576
} ) ;
573
577
574
578
it ( 'should focus second list element when down arrow pressed twice' , function ( ) {
579
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
575
580
$document . find ( 'body' ) . append ( element ) ;
576
581
clickDropdownToggle ( ) ;
577
- triggerKeyDown ( element , 40 ) ;
578
- triggerKeyDown ( element , 40 ) ;
582
+ triggerKeyDown ( dropdownMenu , 40 ) ;
583
+ triggerKeyDown ( dropdownMenu , 40 ) ;
579
584
580
585
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
581
586
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 1 ) ;
582
587
expect ( focusEl ) . toHaveFocus ( ) ;
583
588
} ) ;
584
589
585
590
it ( 'should not focus first list element when up arrow pressed after dropdown toggled' , function ( ) {
591
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
586
592
$document . find ( 'body' ) . append ( element ) ;
587
593
clickDropdownToggle ( ) ;
588
594
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
589
595
590
- triggerKeyDown ( element , 38 ) ;
596
+ triggerKeyDown ( dropdownMenu , 38 ) ;
591
597
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
592
598
expect ( focusEl ) . not . toHaveFocus ( ) ;
593
599
} ) ;
594
600
595
601
it ( 'should focus last list element when up arrow pressed after dropdown toggled' , function ( ) {
602
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
596
603
$document . find ( 'body' ) . append ( element ) ;
597
604
clickDropdownToggle ( ) ;
598
- triggerKeyDown ( element , 38 ) ;
605
+ triggerKeyDown ( dropdownMenu , 38 ) ;
599
606
600
607
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
601
608
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 1 ) ;
602
609
expect ( focusEl ) . toHaveFocus ( ) ;
603
610
} ) ;
604
611
605
612
it ( 'should not change focus when other keys are pressed' , function ( ) {
613
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
606
614
$document . find ( 'body' ) . append ( element ) ;
607
615
clickDropdownToggle ( ) ;
608
- triggerKeyDown ( element , 37 ) ;
616
+ triggerKeyDown ( dropdownMenu , 37 ) ;
609
617
610
618
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
611
619
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) ;
@@ -614,23 +622,25 @@ describe('uib-dropdown', function() {
614
622
} ) ;
615
623
616
624
it ( 'should focus first list element when down arrow pressed 2x and up pressed 1x' , function ( ) {
625
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
617
626
$document . find ( 'body' ) . append ( element ) ;
618
627
clickDropdownToggle ( ) ;
619
- triggerKeyDown ( element , 40 ) ;
620
- triggerKeyDown ( element , 40 ) ;
628
+ triggerKeyDown ( dropdownMenu , 40 ) ;
629
+ triggerKeyDown ( dropdownMenu , 40 ) ;
621
630
622
- triggerKeyDown ( element , 38 ) ;
631
+ triggerKeyDown ( dropdownMenu , 38 ) ;
623
632
624
633
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
625
634
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
626
635
expect ( focusEl ) . toHaveFocus ( ) ;
627
636
} ) ;
628
637
629
638
it ( 'should stay focused on final list element if down pressed at list end' , function ( ) {
639
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
630
640
$document . find ( 'body' ) . append ( element ) ;
631
641
clickDropdownToggle ( ) ;
632
- triggerKeyDown ( element , 40 ) ;
633
- triggerKeyDown ( element , 40 ) ;
642
+ triggerKeyDown ( dropdownMenu , 40 ) ;
643
+ triggerKeyDown ( dropdownMenu , 40 ) ;
634
644
635
645
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
636
646
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 1 ) ;
@@ -642,16 +652,17 @@ describe('uib-dropdown', function() {
642
652
643
653
it ( 'should close if esc is pressed while focused' , function ( ) {
644
654
element = dropdown ( 'disabled' ) ;
655
+ var dropdownMenu = element . find ( '[uib-dropdown-menu]' ) ;
645
656
$document . find ( 'body' ) . append ( element ) ;
646
657
clickDropdownToggle ( ) ;
647
658
648
- triggerKeyDown ( element , 40 ) ;
659
+ triggerKeyDown ( dropdownMenu , 40 ) ;
649
660
650
661
expect ( element ) . toHaveClass ( dropdownConfig . openClass ) ;
651
662
var focusEl = element . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
652
663
expect ( focusEl ) . toHaveFocus ( ) ;
653
664
654
- triggerKeyDown ( element , 27 ) ;
665
+ triggerKeyDown ( dropdownMenu , 27 ) ;
655
666
expect ( element ) . not . toHaveClass ( dropdownConfig . openClass ) ;
656
667
} ) ;
657
668
@@ -667,22 +678,21 @@ describe('uib-dropdown', function() {
667
678
it ( 'should focus first list element when down arrow pressed' , function ( ) {
668
679
clickDropdownToggle ( ) ;
669
680
670
- triggerKeyDown ( element , 40 ) ;
671
-
672
681
var dropdownMenu = $document . find ( '#dropdown-menu' ) ;
673
682
683
+ triggerKeyDown ( dropdownMenu , 40 ) ;
684
+
674
685
expect ( dropdownMenu . parent ( ) ) . toHaveClass ( dropdownConfig . appendToOpenClass ) ;
675
686
var focusEl = $document . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) ;
676
687
expect ( focusEl ) . toHaveFocus ( ) ;
677
688
} ) ;
678
689
679
690
it ( 'should focus second list element when down arrow pressed twice' , function ( ) {
680
691
clickDropdownToggle ( ) ;
681
- triggerKeyDown ( element , 40 ) ;
682
- triggerKeyDown ( element , 40 ) ;
683
- triggerKeyDown ( element , 40 ) ;
684
-
685
692
var dropdownMenu = $document . find ( '#dropdown-menu' ) ;
693
+ triggerKeyDown ( dropdownMenu , 40 ) ;
694
+ triggerKeyDown ( dropdownMenu , 40 ) ;
695
+ triggerKeyDown ( dropdownMenu , 40 ) ;
686
696
687
697
expect ( dropdownMenu . parent ( ) ) . toHaveClass ( dropdownConfig . appendToOpenClass ) ;
688
698
var elem1 = $document . find ( 'ul' ) ;
0 commit comments