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
{{ message }}
This repository was archived by the owner on May 29, 2019. It is now read-only.
Add typeahead-focus-first option to prevent first match from being
focused.
Currently, the first result is automatically focused as you type. Now, set
`typeahead-focus-first="false"` and the first result is *not*
automatically focused as you type.
Closes#908Closes#2916
@@ -409,7 +414,7 @@ describe('typeahead tests', function () {
409
414
triggerKeyDown(element,38);
410
415
expect(element).toBeOpenWithActive(2,1);
411
416
412
-
// Up arrow key goes back to last element
417
+
// Up arrow key goes back to first element
413
418
triggerKeyDown(element,38);
414
419
expect(element).toBeOpenWithActive(2,0);
415
420
});
@@ -670,4 +675,92 @@ describe('typeahead tests', function () {
670
675
});
671
676
});
672
677
678
+
describe('focus first',function(){
679
+
it('should focus the first element by default',function(){
680
+
varelement=prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue"></div>');
681
+
changeInputValueTo(element,'b');
682
+
expect(element).toBeOpenWithActive(2,0);
683
+
684
+
// Down arrow key
685
+
triggerKeyDown(element,40);
686
+
expect(element).toBeOpenWithActive(2,1);
687
+
688
+
// Down arrow key goes back to first element
689
+
triggerKeyDown(element,40);
690
+
expect(element).toBeOpenWithActive(2,0);
691
+
692
+
// Up arrow key goes back to last element
693
+
triggerKeyDown(element,38);
694
+
expect(element).toBeOpenWithActive(2,1);
695
+
696
+
// Up arrow key goes back to first element
697
+
triggerKeyDown(element,38);
698
+
expect(element).toBeOpenWithActive(2,0);
699
+
});
700
+
701
+
it('should not focus the first element until keys are pressed',function(){
702
+
varelement=prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue" typeahead-focus-first="false"></div>');
703
+
changeInputValueTo(element,'b');
704
+
expect(element).toBeOpenWithActive(2,-1);
705
+
706
+
// Down arrow key goes to first element
707
+
triggerKeyDown(element,40);
708
+
expect(element).toBeOpenWithActive(2,0);
709
+
710
+
// Down arrow key goes to second element
711
+
triggerKeyDown(element,40);
712
+
expect(element).toBeOpenWithActive(2,1);
713
+
714
+
// Down arrow key goes back to first element
715
+
triggerKeyDown(element,40);
716
+
expect(element).toBeOpenWithActive(2,0);
717
+
718
+
// Up arrow key goes back to last element
719
+
triggerKeyDown(element,38);
720
+
expect(element).toBeOpenWithActive(2,1);
721
+
722
+
// Up arrow key goes back to first element
723
+
triggerKeyDown(element,38);
724
+
expect(element).toBeOpenWithActive(2,0);
725
+
726
+
// New input goes back to no focus
727
+
changeInputValueTo(element,'a');
728
+
changeInputValueTo(element,'b');
729
+
expect(element).toBeOpenWithActive(2,-1);
730
+
731
+
// Up arrow key goes to last element
732
+
triggerKeyDown(element,38);
733
+
expect(element).toBeOpenWithActive(2,1);
734
+
});
735
+
});
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
+
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>');
743
+
changeInputValueTo(element,'b');
744
+
745
+
// enter key should not be captured when nothing is focused
0 commit comments