You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -258,7 +262,7 @@ describe('typeahead tests', function () {
258
262
return$scope.source;
259
263
};
260
264
varelement=prepareInputEl("<div><input ng-model='result' typeahead='item for item in loadMatches($viewValue) | filter:$viewValue' typeahead-wait-ms='200'></div>");
261
-
265
+
262
266
changeInputValueTo(element,'first');
263
267
$timeout.flush();
264
268
@@ -389,7 +393,7 @@ describe('typeahead tests', function () {
389
393
triggerKeyDown(element,38);
390
394
expect(element).toBeOpenWithActive(2,1);
391
395
392
-
// Up arrow key goes back to last element
396
+
// Up arrow key goes back to first element
393
397
triggerKeyDown(element,38);
394
398
expect(element).toBeOpenWithActive(2,0);
395
399
});
@@ -634,4 +638,93 @@ describe('typeahead tests', function () {
634
638
});
635
639
});
636
640
641
+
describe('focus first',function(){
642
+
it('should focus the first element by default',function(){
643
+
varelement=prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue"></div>');
644
+
changeInputValueTo(element,'b');
645
+
expect(element).toBeOpenWithActive(2,0);
646
+
647
+
// Down arrow key
648
+
triggerKeyDown(element,40);
649
+
expect(element).toBeOpenWithActive(2,1);
650
+
651
+
// Down arrow key goes back to first element
652
+
triggerKeyDown(element,40);
653
+
expect(element).toBeOpenWithActive(2,0);
654
+
655
+
// Up arrow key goes back to last element
656
+
triggerKeyDown(element,38);
657
+
expect(element).toBeOpenWithActive(2,1);
658
+
659
+
// Up arrow key goes back to first element
660
+
triggerKeyDown(element,38);
661
+
expect(element).toBeOpenWithActive(2,0);
662
+
});
663
+
664
+
it('should not focus the first element until keys are pressed',function(){
665
+
varelement=prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue" typeahead-focus-first="false"></div>');
666
+
changeInputValueTo(element,'b');
667
+
expect(element).toBeOpenWithActive(2,-1);
668
+
669
+
// Down arrow key goes to first element
670
+
triggerKeyDown(element,40);
671
+
expect(element).toBeOpenWithActive(2,0);
672
+
673
+
// Down arrow key goes to second element
674
+
triggerKeyDown(element,40);
675
+
expect(element).toBeOpenWithActive(2,1);
676
+
677
+
// Down arrow key goes back to first element
678
+
triggerKeyDown(element,40);
679
+
expect(element).toBeOpenWithActive(2,0);
680
+
681
+
// Up arrow key goes back to last element
682
+
triggerKeyDown(element,38);
683
+
expect(element).toBeOpenWithActive(2,1);
684
+
685
+
// Up arrow key goes back to first element
686
+
triggerKeyDown(element,38);
687
+
expect(element).toBeOpenWithActive(2,0);
688
+
689
+
// New input goes back to no focus
690
+
changeInputValueTo(element,'a');
691
+
changeInputValueTo(element,'b');
692
+
expect(element).toBeOpenWithActive(2,-1);
693
+
694
+
// Up arrow key goes to last element
695
+
triggerKeyDown(element,38);
696
+
expect(element).toBeOpenWithActive(2,1);
697
+
});
698
+
});
699
+
700
+
it('should not capture enter or tab until an item is focused',function(){
701
+
$scope.select_count=0;
702
+
$scope.onSelect=function($item,$model,$label){
703
+
$scope.select_count=$scope.select_count+1;
704
+
};
705
+
varelement=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>');
706
+
changeInputValueTo(element,'b');
707
+
708
+
// enter key should not be captured when nothing is focused
0 commit comments