Skip to content

Commit

Permalink
fix(list-key-manager): don't focus disabled items in typeahead mode (#…
Browse files Browse the repository at this point in the history
…7382)

Fixes the list key manager attempting to focus disabled items in typeahead mode.
crisbeto authored and andrewseguin committed Sep 29, 2017

Verified

This commit was signed with the committer’s verified signature.
thaJeztah Sebastiaan van Stijn
1 parent 53c42a4 commit 1823b2f
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/cdk/a11y/list-key-manager.spec.ts
Original file line number Diff line number Diff line change
@@ -481,6 +481,16 @@ describe('Key managers', () => {
expect(keyManager.activeItem).toBe(itemList.items[0]);
}));

it('should not focus disabled items', fakeAsync(() => {
expect(keyManager.activeItem).toBeFalsy();

itemList.items[0].disabled = true;
keyManager.onKeydown(createKeyboardEvent('keydown', 79, undefined, 'o')); // types "o"
tick(debounceInterval);

expect(keyManager.activeItem).toBeFalsy();
}));

});

});
4 changes: 3 additions & 1 deletion src/cdk/a11y/list-key-manager.ts
Original file line number Diff line number Diff line change
@@ -74,7 +74,9 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
const items = this._items.toArray();

for (let i = 0; i < items.length; i++) {
if (items[i].getLabel!().toUpperCase().trim().indexOf(inputString) === 0) {
let item = items[i];

if (!item.disabled && item.getLabel!().toUpperCase().trim().indexOf(inputString) === 0) {
this.setActiveItem(i);
break;
}

0 comments on commit 1823b2f

Please sign in to comment.