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

Commit a3b3e7b

Browse files
devversionkara
authored andcommitted
fix(chips): no longer throw an error when returning focus to input. (#9528)
* An error will be thrown if the chips component is used in combination with an autocomplete. It did not make the chips not useable, the chips just didn't return the focus to the input element. Fixes #9520.
1 parent a1e68d5 commit a3b3e7b

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/components/chips/chips.spec.js

+37
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,43 @@ describe('<md-chips>', function() {
11391139
expect(scope.items[4]).toBe('Acai Berry');
11401140
expect(element.find('input').val()).toBe('');
11411141
}));
1142+
1143+
it('should remove a chip on click and return focus to the input', function() {
1144+
1145+
var template =
1146+
'<md-chips ng-model="items" md-max-chips="1">' +
1147+
'<md-autocomplete ' +
1148+
'md-selected-item="selectedItem" ' +
1149+
'md-search-text="searchText" ' +
1150+
'md-items="item in querySearch(searchText)" ' +
1151+
'md-item-text="item">' +
1152+
'<span md-highlight-text="searchText">{{itemtype}}</span>' +
1153+
'</md-autocomplete>' +
1154+
'</md-chips>';
1155+
1156+
setupScopeForAutocomplete();
1157+
1158+
var element = buildChips(template);
1159+
1160+
document.body.appendChild(element[0]);
1161+
1162+
// Flush the autocomplete's init timeout.
1163+
$timeout.flush();
1164+
1165+
var input = element.find('input');
1166+
var removeButton = element[0].querySelector('.md-chip-remove');
1167+
1168+
expect(scope.items.length).toBe(3);
1169+
1170+
angular.element(removeButton).triggerHandler('click');
1171+
1172+
$timeout.flush();
1173+
1174+
expect(scope.items.length).toBe(2);
1175+
expect(document.activeElement).toBe(input[0]);
1176+
1177+
element.remove();
1178+
});
11421179
});
11431180

11441181
describe('user input templates', function() {

src/components/chips/js/chipsController.js

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ function MdChipsCtrl ($scope, $attrs, $mdConstant, $log, $element, $timeout, $md
2929
/** @type {angular.$scope} */
3030
this.parent = $scope.$parent;
3131

32+
/** @type {$mdUtil} */
33+
this.$mdUtil = $mdUtil;
34+
3235
/** @type {$log} */
3336
this.$log = $log;
3437

0 commit comments

Comments
 (0)