@@ -734,4 +734,33 @@ describe('typeahead tests', function () {
734
734
} ) ;
735
735
} ) ;
736
736
737
+ it ( 'should not capture enter or tab until an item is focused' , function ( ) {
738
+ $scope . select_count = 0 ;
739
+ $scope . onSelect = function ( $item , $model , $label ) {
740
+ $scope . select_count = $scope . select_count + 1 ;
741
+ } ;
742
+ var element = prepareInputEl ( '<div><input ng-model="result" ng-keydown="keyDownEvent = $event" typeahead="item for item in source | filter:$viewValue" typeahead-on-select="onSelect($item, $model, $label)" typeahead-focus-first="false"></div>' ) ;
743
+ changeInputValueTo ( element , 'b' ) ;
744
+
745
+ // enter key should not be captured when nothing is focused
746
+ triggerKeyDown ( element , 13 ) ;
747
+ expect ( $scope . keyDownEvent . isDefaultPrevented ( ) ) . toBeFalsy ( ) ;
748
+ expect ( $scope . select_count ) . toEqual ( 0 ) ;
749
+
750
+ // tab key should not be captured when nothing is focused
751
+ triggerKeyDown ( element , 9 ) ;
752
+ expect ( $scope . keyDownEvent . isDefaultPrevented ( ) ) . toBeFalsy ( ) ;
753
+ expect ( $scope . select_count ) . toEqual ( 0 ) ;
754
+
755
+ // down key should be captured and focus first element
756
+ triggerKeyDown ( element , 40 ) ;
757
+ expect ( $scope . keyDownEvent . isDefaultPrevented ( ) ) . toBeTruthy ( ) ;
758
+ expect ( element ) . toBeOpenWithActive ( 2 , 0 ) ;
759
+
760
+ // enter key should be captured now that something is focused
761
+ triggerKeyDown ( element , 13 ) ;
762
+ expect ( $scope . keyDownEvent . isDefaultPrevented ( ) ) . toBeTruthy ( ) ;
763
+ expect ( $scope . select_count ) . toEqual ( 1 ) ;
764
+ } ) ;
765
+
737
766
} ) ;
0 commit comments