Skip to content

Commit

Permalink
fix(list-key-manager): exception when no initial active item (#3431)
Browse files Browse the repository at this point in the history
* fix(list-key-manager): exception when no initial active item

Fixes an exception that is thrown when the user presses a key on ListKeyManager that doesn't have a default active item. The problem was due to the fact that we have a check for `null` a little bit down, that handles cases like this, however the active index is `undefined` by default.

Fixes #3317.

* fix: it it
  • Loading branch information
crisbeto authored and tinayuangao committed Mar 7, 2017
1 parent b135b64 commit 842896b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/lib/core/a11y/list-key-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ describe('Key managers', () => {
expect(TAB_EVENT.defaultPrevented).toBe(false);
});

it('should activate the first item when pressing down on a clean key manager', () => {
keyManager = new ListKeyManager<FakeFocusable>(itemList);

expect(keyManager.activeItemIndex).toBeNull('Expected active index to default to null.');

keyManager.onKeydown(DOWN_ARROW_EVENT);

expect(keyManager.activeItemIndex).toBe(0, 'Expected first item to become active.');
});

});

describe('programmatic focus', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/a11y/list-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface CanDisable {
* of items, it will set the active item correctly when arrow events occur.
*/
export class ListKeyManager<T extends CanDisable> {
private _activeItemIndex: number;
private _activeItemIndex: number = null;
private _activeItem: T;
private _tabOut: Subject<any> = new Subject();
private _wrap: boolean = false;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tabs/tab-body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('MdTabBody', () => {
}));
});

it('it should toggle the canBeAnimated flag', () => {
it('should toggle the canBeAnimated flag', () => {
let fixture: ComponentFixture<SimpleTabBodyApp>;
let tabBody: MdTabBody;

Expand Down

0 comments on commit 842896b

Please sign in to comment.