Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit a852e5f

Browse files
committed
test(typeahead): focus-first handles preventDefault on enter/tab
1 parent 052eacb commit a852e5f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Diff for: src/typeahead/test/typeahead.spec.js

+29
Original file line numberDiff line numberDiff line change
@@ -734,4 +734,33 @@ describe('typeahead tests', function () {
734734
});
735735
});
736736

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+
737766
});

0 commit comments

Comments
 (0)