Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(chips): no longer throw an error when returning focus to input. (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
devversion authored and kara committed Sep 10, 2016
1 parent a1e68d5 commit a3b3e7b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/components/chips/chips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,43 @@ describe('<md-chips>', function() {
expect(scope.items[4]).toBe('Acai Berry');
expect(element.find('input').val()).toBe('');
}));

it('should remove a chip on click and return focus to the input', function() {

var template =
'<md-chips ng-model="items" md-max-chips="1">' +
'<md-autocomplete ' +
'md-selected-item="selectedItem" ' +
'md-search-text="searchText" ' +
'md-items="item in querySearch(searchText)" ' +
'md-item-text="item">' +
'<span md-highlight-text="searchText">{{itemtype}}</span>' +
'</md-autocomplete>' +
'</md-chips>';

setupScopeForAutocomplete();

var element = buildChips(template);

document.body.appendChild(element[0]);

// Flush the autocomplete's init timeout.
$timeout.flush();

var input = element.find('input');
var removeButton = element[0].querySelector('.md-chip-remove');

expect(scope.items.length).toBe(3);

angular.element(removeButton).triggerHandler('click');

$timeout.flush();

expect(scope.items.length).toBe(2);
expect(document.activeElement).toBe(input[0]);

element.remove();
});
});

describe('user input templates', function() {
Expand Down
3 changes: 3 additions & 0 deletions src/components/chips/js/chipsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function MdChipsCtrl ($scope, $attrs, $mdConstant, $log, $element, $timeout, $md
/** @type {angular.$scope} */
this.parent = $scope.$parent;

/** @type {$mdUtil} */
this.$mdUtil = $mdUtil;

/** @type {$log} */
this.$log = $log;

Expand Down

0 comments on commit a3b3e7b

Please sign in to comment.