@@ -761,6 +761,52 @@ describe('$uibModal', function() {
761
761
762
762
initialPage . remove ( ) ;
763
763
} ) ;
764
+
765
+ it ( 'should change focus to next non-hidden element when tab is pressed' , function ( ) {
766
+ var initialPage = angular . element ( '<a href="#" id="cannot-get-focus-from-modal">Outland link</a>' ) ;
767
+ angular . element ( document . body ) . append ( initialPage ) ;
768
+ initialPage . focus ( ) ;
769
+
770
+ open ( {
771
+ template :'<a href="#" id="tab-focus-link1">a</a><a href="#" id="tab-focus-link2">b</a><a href="#" id="tab-focus-link3">c</a>' +
772
+ '<button id="tab-focus-button">Open me!</button>' ,
773
+ keyboard : false
774
+ } ) ;
775
+ $rootScope . $digest ( ) ;
776
+ expect ( $document ) . toHaveModalsOpen ( 1 ) ;
777
+
778
+ $ ( '#tab-focus-link3' ) . focus ( ) ;
779
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-link3' ) ;
780
+
781
+ $ ( '#tab-focus-button' ) . css ( 'display' , 'none' ) ;
782
+ triggerKeyDown ( angular . element ( document . activeElement ) , 9 , false ) ;
783
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-link1' ) ;
784
+
785
+ initialPage . remove ( ) ;
786
+ } ) ;
787
+
788
+ it ( 'should change focus to previous non-hidden element when shift+tab is pressed' , function ( ) {
789
+ var initialPage = angular . element ( '<a href="#" id="cannot-get-focus-from-modal">Outland link</a>' ) ;
790
+ angular . element ( document . body ) . append ( initialPage ) ;
791
+ initialPage . focus ( ) ;
792
+
793
+ open ( {
794
+ template :'<a href="#" id="tab-focus-link1">a</a><a href="#" id="tab-focus-link2">b</a><a href="#" id="tab-focus-link3">c</a>' +
795
+ '<button id="tab-focus-button">Open me!</button>' ,
796
+ keyboard : false
797
+ } ) ;
798
+ $rootScope . $digest ( ) ;
799
+ expect ( $document ) . toHaveModalsOpen ( 1 ) ;
800
+
801
+ $ ( '#tab-focus-link1' ) . focus ( ) ;
802
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-link1' ) ;
803
+
804
+ $ ( '#tab-focus-button' ) . css ( 'display' , 'none' ) ;
805
+ triggerKeyDown ( angular . element ( document . activeElement ) , 9 , true ) ;
806
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-link3' ) ;
807
+
808
+ initialPage . remove ( ) ;
809
+ } ) ;
764
810
} ) ;
765
811
766
812
describe ( 'default options can be changed in a provider' , function ( ) {
0 commit comments