Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/lib/chips/chip-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/chips/chip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down