Skip to content
Closed
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/cdk/a11y/key-manager/list-key-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ describe('Key managers', () => {
expect(keyManager.activeItem).toBeNull();
});

it('should reset the activeItem to null if it is removed from the QueryList', () => {
expect(keyManager.activeItemIndex).toBe(0);
expect(keyManager.activeItem!.getLabel()).toBe('one');

itemList.items.splice(0);
itemList.notifyOnChanges();

expect(keyManager.activeItemIndex).toBe(-1);
expect(keyManager.activeItem).toBeNull();

});

describe('Key events', () => {

it('should emit tabOut when the tab key is pressed', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/cdk/a11y/key-manager/list-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export class ListKeyManager<T extends ListKeyManagerOption> {

if (newIndex > -1 && newIndex !== this._activeItemIndex) {
this._activeItemIndex = newIndex;
} else {
this._activeItemIndex = -1;
this._activeItem = null;
}
}
});
Expand Down