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.
  • Loading branch information
crisbeto authored and andrewseguin committed Sep 29, 2017
1 parent 53c42a4 commit 1823b2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/cdk/a11y/list-key-manager.spec.ts
Expand Up @@ -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();
}));

});

});
Expand Down
4 changes: 3 additions & 1 deletion src/cdk/a11y/list-key-manager.ts
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1823b2f

Please sign in to comment.