fix(list-key-manager): don't focus disabled items in typeahead mode (#7382)

Fixes the list key manager attempting to focus disabled items in typeahead mode.
This commit is contained in:
Kristiyan Kostadinov
2017-09-29 21:58:12 +02:00
committed by Andrew Seguin
parent 53c42a45ca
commit 1823b2fa8e
2 changed files with 13 additions and 1 deletions
+10
View File
@@ -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();
}));
});
});
+3 -1
View File
@@ -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;
}