From 542759feed16c6739ed9170b4cc7e9f68ed0a707 Mon Sep 17 00:00:00 2001 From: DevVersion Date: Fri, 25 Mar 2016 16:12:38 +0100 Subject: [PATCH] fix(chips): do not trim the input model. * 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 #7243 --- src/components/chips/chips.spec.js | 29 +++++++++++++++++++++++ src/components/chips/js/chipsDirective.js | 1 + 2 files changed, 30 insertions(+) diff --git a/src/components/chips/chips.spec.js b/src/components/chips/chips.spec.js index 8efd637f486..81ffb208583 100755 --- a/src/components/chips/chips.spec.js +++ b/src/components/chips/chips.spec.js @@ -388,8 +388,37 @@ describe('', 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'); diff --git a/src/components/chips/js/chipsDirective.js b/src/components/chips/js/chipsDirective.js index 62c0c402145..b4c86cd81a1 100644 --- a/src/components/chips/js/chipsDirective.js +++ b/src/components/chips/js/chipsDirective.js @@ -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 = '\