Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(autocomplete): only 2 messages will be displayed at any given tim…
Browse files Browse the repository at this point in the history
…e for autocomplete

Closes #2785
  • Loading branch information
Robert Messerle committed Jun 1, 2015
1 parent c100ef1 commit 6b4e95c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions src/components/autocomplete/js/autocompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
event.preventDefault();
self.index = Math.min(self.index + 1, self.matches.length - 1);
updateScroll();
updateSelectionMessage();
updateMessages();
break;
case $mdConstant.KEY_CODE.UP_ARROW:
if (self.loading) return;
event.preventDefault();
self.index = self.index < 0 ? self.matches.length - 1 : Math.max(0, self.index - 1);
updateScroll();
updateSelectionMessage();
updateMessages();
break;
case $mdConstant.KEY_CODE.TAB:
case $mdConstant.KEY_CODE.ENTER:
Expand Down Expand Up @@ -334,18 +334,16 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $
}

function updateMessages () {
if (self.hidden) return;
switch (self.matches.length) {
case 0: return self.messages.splice(0);
case 1: return self.messages.push({ display: 'There is 1 match available.' });
default: return self.messages.push({ display: 'There are '
+ self.matches.length
+ ' matches available.' });
}
self.messages = self.matches.length
? [ getCountMessage(), getCurrentDisplayValue() ]
: [];
}

function updateSelectionMessage () {
self.messages.push({ display: getCurrentDisplayValue() });
function getCountMessage () {
switch (self.matches.length) {
case 1: return 'There is 1 match available.';
default: return 'There are ' + self.matches.length + ' matches available.';
}
}

function updateScroll () {
Expand Down
2 changes: 1 addition & 1 deletion src/components/autocomplete/js/autocompleteDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function MdAutocomplete ($mdTheming, $mdUtil) {
class="md-visually-hidden"\
role="status"\
aria-live="assertive">\
<p ng-repeat="message in $mdAutocompleteCtrl.messages">{{message.display}}</p>\
<p ng-repeat="message in $mdAutocompleteCtrl.messages" ng-if="message">{{message}}</p>\
</aria-status>';

function getItemTemplate() {
Expand Down

0 comments on commit 6b4e95c

Please sign in to comment.