@@ -23,6 +23,11 @@ describe('dropdownToggle', function() {
23
23
elm . find ( 'a[dropdown-toggle]' ) . click ( ) ;
24
24
} ;
25
25
26
+ var clickDropdownButtonToggle = function ( elm ) {
27
+ elm = elm || element ;
28
+ elm . find ( 'button[dropdown-toggle]' ) . click ( ) ;
29
+ } ;
30
+
26
31
var triggerKeyDown = function ( element , keyCode ) {
27
32
var e = $ . Event ( 'keydown' ) ;
28
33
e . which = keyCode ;
@@ -673,4 +678,40 @@ describe('dropdownToggle', function() {
673
678
expect ( isFocused ( focusEl ) ) . toBe ( true ) ;
674
679
} ) ;
675
680
} ) ;
681
+
682
+ describe ( 'button dropdown menu with `keyboard-nav` option with `dropdown-append-to-body` option - #4091' , function ( ) {
683
+ function dropdown ( ) {
684
+ return $compile ( '<div dropdown keyboard-nav dropdown-append-to-body><button dropdown-toggle>Dropdown on Body</button><ul class="dropdown-menu"><li><a>Hello on Body</a></li><li><a>Hello Again</a></li></ul></div>' ) ( $rootScope ) ;
685
+ }
686
+
687
+ beforeEach ( function ( ) {
688
+ element = dropdown ( ) ;
689
+ } ) ;
690
+
691
+ it ( 'should focus first list element when down arrow pressed' , function ( ) {
692
+ clickDropdownButtonToggle ( ) ;
693
+
694
+ triggerKeyDown ( $document , 40 ) ;
695
+
696
+ expect ( element . hasClass ( dropdownConfig . openClass ) ) . toBe ( true ) ;
697
+ expect ( element . controller ( 'dropdown' ) . selectedOption ) . toBe ( 0 ) ; // document.activeElement won't be <li>
698
+ } ) ;
699
+
700
+ it ( 'should not focus first list element when down arrow pressed if closed' , function ( ) {
701
+ triggerKeyDown ( $document , 40 ) ;
702
+
703
+ expect ( element . hasClass ( dropdownConfig . openClass ) ) . toBe ( false ) ;
704
+ var focusEl = $document . find ( 'ul' ) . eq ( 0 ) . find ( 'a' ) ;
705
+ expect ( isFocused ( focusEl ) ) . toBe ( false ) ;
706
+ } ) ;
707
+
708
+ it ( 'should focus second list element when down arrow pressed twice' , function ( ) {
709
+ clickDropdownButtonToggle ( ) ;
710
+ triggerKeyDown ( $document , 40 ) ;
711
+ triggerKeyDown ( $document , 40 ) ;
712
+
713
+ expect ( element . hasClass ( dropdownConfig . openClass ) ) . toBe ( true ) ;
714
+ expect ( element . controller ( 'dropdown' ) . selectedOption ) . toBe ( 1 ) ; // document.activeElement won't be <li>
715
+ } ) ;
716
+ } ) ;
676
717
} ) ;
0 commit comments