diff --git a/src/lib/chips/chip-list.spec.ts b/src/lib/chips/chip-list.spec.ts index dda5c16f2ee..752f05cb97c 100644 --- a/src/lib/chips/chip-list.spec.ts +++ b/src/lib/chips/chip-list.spec.ts @@ -212,6 +212,18 @@ describe('MatChipList', () => { expect(manager.activeItemIndex).toEqual(1); }); + it('should not handle arrow key events from non-chip elements', () => { + const event: KeyboardEvent = + createKeyboardEvent('keydown', RIGHT_ARROW, chipListNativeElement); + const initialActiveIndex = manager.activeItemIndex; + + chipListInstance._keydown(event); + fixture.detectChanges(); + + expect(manager.activeItemIndex) + .toBe(initialActiveIndex, 'Expected focused item not to have changed.'); + }); + }); describe('RTL', () => { diff --git a/src/lib/chips/chip-list.ts b/src/lib/chips/chip-list.ts index ff2620dbcae..8f4963a9a03 100644 --- a/src/lib/chips/chip-list.ts +++ b/src/lib/chips/chip-list.ts @@ -459,7 +459,7 @@ export class MatChipList extends _MatChipListMixinBase implements MatFormFieldCo if (event.keyCode === BACKSPACE && this._isInputEmpty(target)) { this._keyManager.setLastItemActive(); event.preventDefault(); - } else { + } else if (target && target.classList.contains('mat-chip')) { this._keyManager.onKeydown(event); this.stateChanges.next(); }