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

Commit

Permalink
fix(chips): makes sure that input is cleared when selecting a chip
Browse files Browse the repository at this point in the history
Closes #3575
  • Loading branch information
Robert Messerle committed Jul 14, 2015
1 parent 5f1c94b commit ee1fed1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/autocomplete/js/autocompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
$attrs.$observe('disabled', function (value) { ctrl.isDisabled = value; });
$attrs.$observe('required', function (value) { ctrl.isRequired = value !== null; });
$scope.$watch('searchText', wait ? $mdUtil.debounce(handleSearchText, wait) : handleSearchText);
registerSelectedItemWatcher(selectedItemChange);
$scope.$watch('selectedItem', handleSelectedItemChange);
$scope.$watch('selectedItem', selectedItemChange);
angular.element($window).on('resize', positionDropdown);
$scope.$on('$destroy', cleanup);
}
Expand Down Expand Up @@ -236,6 +235,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
if (selectedItem) {
getDisplayValue(selectedItem).then(function(val) {
$scope.searchText = val;
handleSelectedItemChange(selectedItem, previousSelectedItem);
});
}

Expand All @@ -249,6 +249,9 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
angular.isFunction($scope.itemChange) && $scope.itemChange(getItemAsNameVal($scope.selectedItem));
}

/**
* Use the user-defined expression to announce changes each time the search text is changed
*/
function announceTextChange() {
angular.isFunction($scope.textChange) && $scope.textChange();
}
Expand All @@ -260,9 +263,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
* @param previousSelectedItem
*/
function handleSelectedItemChange(selectedItem, previousSelectedItem) {
for (var i = 0; i < selectedItemWatchers.length; ++i) {
selectedItemWatchers[i](selectedItem, previousSelectedItem);
}
selectedItemWatchers.forEach(function (watcher) { watcher(selectedItem, previousSelectedItem); });
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/components/chips/chips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ describe('<md-chips>', function() {

expect(scope.items.length).toBe(4);
expect(scope.items[3]).toBe('Kiwi');
expect(element.find('input').val()).toBe('');
}));
});

Expand Down

0 comments on commit ee1fed1

Please sign in to comment.