Last active
October 12, 2015 20:06
-
-
Save pjlamb12/3fe98d18275437dad291 to your computer and use it in GitHub Desktop.
ng-class Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="search-results" ng-show="searchKeyword != '' && inputIsFocused"> | |
<li ng-repeat="provider in providerList | searchFilter:searchFilterType:searchKeyword" ng-class="{'highlighted': provider == arrowSelectedItem}" ng-click="setSearchKeyword(provider)">{{provider.name}}</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.arrowSelectedItem = null; | |
$scope.filteredProviderList = null; | |
function moveSelectedItem(direction) { | |
var index = $scope.filteredProviderList.indexOf($scope.arrowSelectedItem); | |
if( direction == 'up' && index <= 0 ) { | |
$scope.arrowSelectedItem = null; | |
} else if( direction == 'up' && index > 0 ) { | |
$scope.arrowSelectedItem = $scope.filteredProviderList[index-1]; | |
} else if( direction == 'down' && index < $scope.filteredProviderList.length - 1 ) { | |
$scope.arrowSelectedItem = $scope.filteredProviderList[index+1]; | |
} | |
} | |
var keyHandler = function(e) { | |
// If they hit enter while they've highlighted an item from the dropdown | |
if( e.keyCode === 13 && $scope.arrowSelectedItem != null ) { | |
$scope.setSearchKeyword($scope.arrowSelectedItem); | |
} | |
if( $scope.searchKeyword.length == 0 ) { | |
$scope.arrowSelectedItem = null; | |
} | |
if( $scope.inputIsFocused && $scope.searchKeyword != '' ) { | |
if( e.keyCode === 38 ) { | |
if( $scope.arrowSelectedItem != null ) { | |
moveSelectedItem('up'); | |
} | |
} else if ( e.keyCode === 40 ) { | |
moveSelectedItem('down'); | |
} | |
} | |
// If a letter key is pressed, filter the list so that our down arrow selection list is correct | |
if ( $scope.inputIsFocused && e.keyCode >= 48 && e.keyCode <= 90 ) { | |
$scope.filteredProviderList = searchFilterFilter($scope.providerList, $scope.searchFilterType, $scope.searchKeyword); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment