fix(chips): chip list capturing keyboard events from input (#9651)

* Fixes the chip list reacting to keyboard events from inside the input, which ends up moving focus away and creating a new chip. This appears to be a regression introduced in 5a055a70d4.
* Adds a test to ensure that we don't re-introduce the issue in the future.
This commit is contained in:
Kristiyan Kostadinov
2018-01-29 21:31:04 +01:00
committed by Jeremy Elbourn
parent e6e4c3c222
commit a48f75b454
2 changed files with 13 additions and 1 deletions
+12
View File
@@ -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', () => {
+1 -1
View File
@@ -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();
}