Skip to content

fix(list-key-manager): not ignoring vertical key events in horizontal-only mode #10075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/cdk/a11y/key-manager/list-key-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ describe('Key managers', () => {
expect(fakeKeyEvents.unsupported.defaultPrevented).toBe(false);
});

it('should ignore the horizontal keys when only in vertical mode', () => {
keyManager.withVerticalOrientation().withHorizontalOrientation(null);

expect(keyManager.activeItemIndex).toBe(0);

keyManager.onKeydown(fakeKeyEvents.rightArrow);

expect(keyManager.activeItemIndex).toBe(0);
expect(fakeKeyEvents.rightArrow.defaultPrevented).toBe(false);
});

it('should ignore the horizontal keys when only in horizontal mode', () => {
keyManager.withVerticalOrientation(false).withHorizontalOrientation('ltr');

expect(keyManager.activeItemIndex).toBe(0);

keyManager.onKeydown(fakeKeyEvents.downArrow);

expect(keyManager.activeItemIndex).toBe(0);
expect(fakeKeyEvents.downArrow.defaultPrevented).toBe(false);
});

describe('with `vertical` direction', () => {
beforeEach(() => {
keyManager.withVerticalOrientation();
Expand Down
8 changes: 8 additions & 0 deletions src/cdk/a11y/key-manager/list-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,16 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
if (this._vertical) {
this.setNextItemActive();
break;
} else {
return;
}

case UP_ARROW:
if (this._vertical) {
this.setPreviousItemActive();
break;
} else {
return;
}

case RIGHT_ARROW:
Expand All @@ -186,6 +190,8 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
} else if (this._horizontal === 'rtl') {
this.setPreviousItemActive();
break;
} else {
return;
}

case LEFT_ARROW:
Expand All @@ -195,6 +201,8 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
} else if (this._horizontal === 'rtl') {
this.setNextItemActive();
break;
} else {
return;
}

default:
Expand Down