@@ -807,6 +807,52 @@ describe('$uibModal', function() {
807
807
808
808
initialPage . remove ( ) ;
809
809
} ) ;
810
+
811
+ it ( 'should change focus to next tabbable element when tab is pressed' , function ( ) {
812
+ var initialPage = angular . element ( '<a href="#" id="cannot-get-focus-from-modal">Outland link</a>' ) ;
813
+ angular . element ( document . body ) . append ( initialPage ) ;
814
+ initialPage . focus ( ) ;
815
+
816
+ open ( {
817
+ template :'<button id="tab-focus-button1" tabindex="-1">Skip me!</button><a href="#" id="tab-focus-link1">a</a>' +
818
+ '<a href="#" id="tab-focus-link2">b</a><a href="#" id="tab-focus-link3">c</a>' +
819
+ '<button id="tab-focus-button2" tabindex="-1">Skip me!</button>' ,
820
+ keyboard : false
821
+ } ) ;
822
+ $rootScope . $digest ( ) ;
823
+ expect ( $document ) . toHaveModalsOpen ( 1 ) ;
824
+
825
+ $ ( '#tab-focus-link3' ) . focus ( ) ;
826
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-link3' ) ;
827
+
828
+ triggerKeyDown ( angular . element ( document . activeElement ) , 9 , false ) ;
829
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-link1' ) ;
830
+
831
+ initialPage . remove ( ) ;
832
+ } ) ;
833
+
834
+ it ( 'should change focus to previous tabbable element when shift+tab is pressed' , function ( ) {
835
+ var initialPage = angular . element ( '<a href="#" id="cannot-get-focus-from-modal">Outland link</a>' ) ;
836
+ angular . element ( document . body ) . append ( initialPage ) ;
837
+ initialPage . focus ( ) ;
838
+
839
+ open ( {
840
+ template :'<button id="tab-focus-button1" tabindex="-1">Skip me!</button><a href="#" id="tab-focus-link1">a</a>' +
841
+ '<a href="#" id="tab-focus-link2">b</a><a href="#" id="tab-focus-link3">c</a>' +
842
+ '<button id="tab-focus-button2" tabindex="-1">Skip me!</button>' ,
843
+ keyboard : false
844
+ } ) ;
845
+ $rootScope . $digest ( ) ;
846
+ expect ( $document ) . toHaveModalsOpen ( 1 ) ;
847
+
848
+ $ ( '#tab-focus-link1' ) . focus ( ) ;
849
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-link1' ) ;
850
+
851
+ triggerKeyDown ( angular . element ( document . activeElement ) , 9 , true ) ;
852
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-link3' ) ;
853
+
854
+ initialPage . remove ( ) ;
855
+ } ) ;
810
856
} ) ;
811
857
812
858
describe ( 'default options can be changed in a provider' , function ( ) {
0 commit comments