Skip to content

Commit f31a2f1

Browse files
crisbetojelbourn
authored andcommitted
fix(list-key-manager): not ignoring vertical key events in horizontal-only mode (#10075)
Fixes the a `ListKeyManager` that is in `horizontal`-only mode not ignoring the vertical key events due it falling into the switch statement.
1 parent f93d0f4 commit f31a2f1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/cdk/a11y/key-manager/list-key-manager.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,28 @@ describe('Key managers', () => {
138138
expect(fakeKeyEvents.unsupported.defaultPrevented).toBe(false);
139139
});
140140

141+
it('should ignore the horizontal keys when only in vertical mode', () => {
142+
keyManager.withVerticalOrientation().withHorizontalOrientation(null);
143+
144+
expect(keyManager.activeItemIndex).toBe(0);
145+
146+
keyManager.onKeydown(fakeKeyEvents.rightArrow);
147+
148+
expect(keyManager.activeItemIndex).toBe(0);
149+
expect(fakeKeyEvents.rightArrow.defaultPrevented).toBe(false);
150+
});
151+
152+
it('should ignore the horizontal keys when only in horizontal mode', () => {
153+
keyManager.withVerticalOrientation(false).withHorizontalOrientation('ltr');
154+
155+
expect(keyManager.activeItemIndex).toBe(0);
156+
157+
keyManager.onKeydown(fakeKeyEvents.downArrow);
158+
159+
expect(keyManager.activeItemIndex).toBe(0);
160+
expect(fakeKeyEvents.downArrow.defaultPrevented).toBe(false);
161+
});
162+
141163
describe('with `vertical` direction', () => {
142164
beforeEach(() => {
143165
keyManager.withVerticalOrientation();

src/cdk/a11y/key-manager/list-key-manager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,16 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
171171
if (this._vertical) {
172172
this.setNextItemActive();
173173
break;
174+
} else {
175+
return;
174176
}
175177

176178
case UP_ARROW:
177179
if (this._vertical) {
178180
this.setPreviousItemActive();
179181
break;
182+
} else {
183+
return;
180184
}
181185

182186
case RIGHT_ARROW:
@@ -186,6 +190,8 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
186190
} else if (this._horizontal === 'rtl') {
187191
this.setPreviousItemActive();
188192
break;
193+
} else {
194+
return;
189195
}
190196

191197
case LEFT_ARROW:
@@ -195,6 +201,8 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
195201
} else if (this._horizontal === 'rtl') {
196202
this.setNextItemActive();
197203
break;
204+
} else {
205+
return;
198206
}
199207

200208
default:

0 commit comments

Comments
 (0)