Skip to content

Commit ffbb425

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 2ece035 commit ffbb425

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
@@ -139,6 +139,28 @@ describe('Key managers', () => {
139139
expect(fakeKeyEvents.unsupported.defaultPrevented).toBe(false);
140140
});
141141

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