Skip to content

Commit

Permalink
fix(chips): do not trim the input model.
Browse files Browse the repository at this point in the history
* The chips input should not trim the text, because otherwise the buffer will be always falsey, even when there are spaces in the input, and this would cause the backspace not to work.

Fixes angular#7243
  • Loading branch information
devversion committed Mar 25, 2016
1 parent 0b89a87 commit 542759f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/components/chips/chips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,37 @@ describe('<md-chips>', function() {
expect(enterEvent.preventDefault).toHaveBeenCalled();
}));

it('should not trim the input text', inject(function($mdConstant) {
var element = buildChips(BASIC_CHIP_TEMPLATE);
var ctrl = element.controller('mdChips');
var input = element.find('input');

input.val(' ');
input.triggerHandler('input');

expect(ctrl.chipBuffer).toBeTruthy();

var enterEvent = {
type: 'keydown',
keyCode: $mdConstant.KEY_CODE.BACKSPACE,
which: $mdConstant.KEY_CODE.BACKSPACE,
preventDefault: jasmine.createSpy('preventDefault')
};

input.triggerHandler(enterEvent);

expect(enterEvent.preventDefault).not.toHaveBeenCalled();

input.val('');
input.triggerHandler('input');

input.triggerHandler(enterEvent);

expect(enterEvent.preventDefault).toHaveBeenCalledTimes(1);
}));
});


it('focuses/blurs the component when focusing/blurring the input', inject(function() {
var element = buildChips(BASIC_CHIP_TEMPLATE);
var ctrl = element.controller('mdChips');
Expand Down
1 change: 1 addition & 0 deletions src/components/chips/js/chipsDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
ng-model="$mdChipsCtrl.chipBuffer"\
ng-focus="$mdChipsCtrl.onInputFocus()"\
ng-blur="$mdChipsCtrl.onInputBlur()"\
ng-trim="false"\
ng-keydown="$mdChipsCtrl.inputKeydown($event)">';

var CHIP_DEFAULT_TEMPLATE = '\
Expand Down

0 comments on commit 542759f

Please sign in to comment.