@@ -527,6 +527,46 @@ describe('$uibModal', function () {
527
527
528
528
initialPage . remove ( ) ;
529
529
} ) ;
530
+
531
+ it ( 'should change focus to first element when tab key is pressed when keyboard is false' , function ( ) {
532
+ var initialPage = angular . element ( '<a href="#" id="cannot-get-focus-from-modal">Outland link</a>' ) ;
533
+ angular . element ( document . body ) . append ( initialPage ) ;
534
+ initialPage . focus ( ) ;
535
+
536
+ open ( {
537
+ template :'<a href="#" id="tab-focus-link"><input type="text" id="tab-focus-input1"/><input type="text" id="tab-focus-input2"/>' +
538
+ '<button id="tab-focus-button">Open me!</button>' ,
539
+ keyboard : false
540
+ } ) ;
541
+ expect ( $document ) . toHaveModalsOpen ( 1 ) ;
542
+
543
+ var lastElement = angular . element ( document . getElementById ( 'tab-focus-button' ) ) ;
544
+ lastElement . focus ( ) ;
545
+ triggerKeyDown ( lastElement , 9 ) ;
546
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-link' ) ;
547
+
548
+ initialPage . remove ( ) ;
549
+ } ) ;
550
+
551
+ it ( 'should change focus to last element when shift+tab keys are pressed when keyboard is false' , function ( ) {
552
+ var initialPage = angular . element ( '<a href="#" id="cannot-get-focus-from-modal">Outland link</a>' ) ;
553
+ angular . element ( document . body ) . append ( initialPage ) ;
554
+ initialPage . focus ( ) ;
555
+
556
+ open ( {
557
+ template :'<a href="#" id="tab-focus-link"><input type="text" id="tab-focus-input1"/><input type="text" id="tab-focus-input2"/>' +
558
+ '<button id="tab-focus-button">Open me!</button>' ,
559
+ keyboard : false
560
+ } ) ;
561
+ expect ( $document ) . toHaveModalsOpen ( 1 ) ;
562
+
563
+ var lastElement = angular . element ( document . getElementById ( 'tab-focus-link' ) ) ;
564
+ lastElement . focus ( ) ;
565
+ triggerKeyDown ( lastElement , 9 , true ) ;
566
+ expect ( document . activeElement . getAttribute ( 'id' ) ) . toBe ( 'tab-focus-button' ) ;
567
+
568
+ initialPage . remove ( ) ;
569
+ } ) ;
530
570
} ) ;
531
571
532
572
describe ( 'default options can be changed in a provider' , function ( ) {
0 commit comments