Skip to content
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
11 changes: 11 additions & 0 deletions src/lib/chips/chip-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,17 @@ describe('MatChipList', () => {
expect(falsyFixture.componentInstance.chips.first.selected)
.toBe(true, 'Expected first option to be selected');
});

it('should not focus the active chip when the value is set programmatically', () => {
const chipArray = fixture.componentInstance.chips.toArray();

spyOn(chipArray[4], 'focus').and.callThrough();

fixture.componentInstance.control.setValue('chips-4');
fixture.detectChanges();

expect(chipArray[4].focus).not.toHaveBeenCalled();
});
});

describe('multiple selection', () => {
Expand Down
10 changes: 8 additions & 2 deletions src/lib/chips/chip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ export class MatChipList implements MatFormFieldControl<any>, ControlValueAccess
private _isInputEmpty(element: HTMLElement): boolean {
if (element && element.nodeName.toLowerCase() === 'input') {
let input = element as HTMLInputElement;

return !input.value;
}

Expand All @@ -547,7 +546,14 @@ export class MatChipList implements MatFormFieldControl<any>, ControlValueAccess
// Shift focus to the active item. Note that we shouldn't do this in multiple
// mode, because we don't know what chip the user interacted with last.
if (correspondingChip) {
this._keyManager.setActiveItem(this.chips.toArray().indexOf(correspondingChip));
const correspondingChipIndex = this.chips.toArray().indexOf(correspondingChip);

if (isUserInput) {
this._keyManager.setActiveItem(correspondingChipIndex);
} else {
this._keyManager.updateActiveItemIndex(correspondingChipIndex);
}

}
}
}
Expand Down