diff --git a/src/lib/chip-field/chip-field-foundation.ts b/src/lib/chip-field/chip-field-foundation.ts index 31cf204a0..83431c9b5 100644 --- a/src/lib/chip-field/chip-field-foundation.ts +++ b/src/lib/chip-field/chip-field-foundation.ts @@ -101,14 +101,6 @@ export class ChipFieldFoundation extends FieldFoundation implements IChipFieldFo case 'Escape': input.value = ''; break; - case 'Tab': - if (this.addMemberOnBlur) { - this._addMember(input); - break; - } else { - input.value = ''; - break; - } default: break; } diff --git a/src/test/spec/chip-field/chip-field.spec.ts b/src/test/spec/chip-field/chip-field.spec.ts index a66194301..c51b16fd0 100644 --- a/src/test/spec/chip-field/chip-field.spec.ts +++ b/src/test/spec/chip-field/chip-field.spec.ts @@ -1215,8 +1215,30 @@ describe('ChipFieldComponent', function(this: ITestContext) { this.context.component.setAttribute(CHIP_FIELD_CONSTANTS.attributes.ADD_MEMBER_ON_BLUR, 'false'); expect(this.context.component.addMemberOnBlur).toBe(false); }); - }); + it('chips should not be added when addMemberOnBlur is set to false and the "Tab" key is pressed', function(this: ITestContext) { + this.context = setupTestContext(); + this.context.component.setAttribute(CHIP_FIELD_CONSTANTS.attributes.ADD_MEMBER_ON_BLUR, 'false'); + const listener = jasmine.createSpy('add member listener'); + this.context.component.addEventListener(CHIP_FIELD_CONSTANTS.events.MEMBER_ADDED, listener); + getNativeInput(this.context.component).value = 'test'; + dispatchKeydownEvent(getNativeInput(this.context.component), 'Tab'); + expect(listener).toHaveBeenCalledTimes(0) + expect(getNativeInput(this.context.component).value).withContext('the input value should have been cleared').toBe(''); + }); + + + it('chips should be added when addMemberOnBlur is set to true and the mouse is clicked outside of the input', function(this: ITestContext) { + this.context = setupTestContext(); + this.context.component.setAttribute(CHIP_FIELD_CONSTANTS.attributes.ADD_MEMBER_ON_BLUR, 'true'); + const listener = jasmine.createSpy('add member listener'); + this.context.component.addEventListener(CHIP_FIELD_CONSTANTS.events.MEMBER_ADDED, listener); + getNativeInput(this.context.component).value = 'test'; + getNativeInput(this.context.component).focus(); + getNativeInput(this.context.component).blur(); + expect(listener).toHaveBeenCalledTimes(1) + }); + }); }); describe('With no label', function(this: ITestContext) { @@ -1295,4 +1317,9 @@ describe('ChipFieldComponent', function(this: ITestContext) { component.append(chip); return chip; } + + function checkIfAChipWasAdded(component: IChipFieldComponent): number { + let test = component.querySelectorAll('forge-chip'); + return test.length; + } });