Skip to content

Commit

Permalink
fix(cdk/a11y): allows disabled items to receive initial focus
Browse files Browse the repository at this point in the history
  • Loading branch information
BobobUnicorn committed Dec 19, 2023
1 parent 7dea4fb commit f160dc1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
14 changes: 2 additions & 12 deletions src/cdk/a11y/key-manager/tree-key-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,8 @@ describe('TreeKeyManager', () => {
itemList.notifyOnChanges();
});

it('does not initialize with the first item activated', () => {
expect(keyManager.getActiveItemIndex()).withContext('active item index').toBe(-1);
});

it('if an item is subsequently enabled, activates it', () => {
itemList.reset([
new itemParam.constructor('Bilbo', true),
new itemParam.constructor('Frodo', false),
new itemParam.constructor('Pippin', true),
]);
itemList.notifyOnChanges();
expect(keyManager.getActiveItemIndex()).withContext('active item index').toBe(1);
it('initializes with the first item activated', () => {
expect(keyManager.getActiveItemIndex()).withContext('active item index').toBe(0);
});
});

Expand Down
6 changes: 1 addition & 5 deletions src/cdk/a11y/key-manager/tree-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,14 @@ export class TreeKeyManager<T extends TreeKeyManagerItem> implements TreeKeyMana
return;
}

let focusIndex = -1;
let focusIndex = 0;
for (let i = 0; i < this._items.length; i++) {
if (!this._skipPredicateFn(this._items[i]) && !this._isItemDisabled(this._items[i])) {
focusIndex = i;
break;
}
}

if (focusIndex === -1) {
return;
}

this.focusItem(focusIndex);
this._hasInitialFocused = true;
}
Expand Down

0 comments on commit f160dc1

Please sign in to comment.