Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Commit

Permalink
fix(autocomplete): Fix suggestion selection on touch devices
Browse files Browse the repository at this point in the history
Perform suggestion selection on mouse click instead of mouse enter so
it works correctly on touch devices.

Close #142
  • Loading branch information
mbenford committed Jul 7, 2014
1 parent 9714f8a commit ef25a55
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/auto-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ tagsInput.directive('autoComplete', function($document, $timeout, $sce, tagsInpu

scope.suggestionList = suggestionList;

scope.addSuggestionByIndex = function(index) {
suggestionList.select(index);
scope.addSuggestion();
};

scope.addSuggestion = function() {
var added = false;

Expand Down
2 changes: 1 addition & 1 deletion templates/auto-complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<li class="suggestion-item"
ng-repeat="item in suggestionList.items track by track(item)"
ng-class="{selected: item == suggestionList.selected}"
ng-click="addSuggestion()"
ng-click="addSuggestionByIndex($index)"
ng-mouseenter="suggestionList.select($index)"
ng-bind-html="highlight(item)"></li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions test/auto-complete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,13 @@ describe('autoComplete directive', function() {

it('adds the selected suggestion when a mouse click is triggered', function() {
// Arrange
getSuggestion(1).mouseenter();
suggestionList.selected = null;

// Act
getSuggestion(1).click();
getSuggestion(0).click();

// Assert
expect(tagsInput.addTag).toHaveBeenCalledWith({ text: 'Item2' });
expect(tagsInput.addTag).toHaveBeenCalledWith({ text: 'Item1' });
});

it('focuses the input field when a suggestion is added via a mouse click', function() {
Expand Down

0 comments on commit ef25a55

Please sign in to comment.