Skip to content

Commit 4a647a5

Browse files
committed
fix(a11y): don't handle disallowed modifier keys in typeahead mode
Recently we switched to skip handling keyboard events with modifiers, unless the consumer opted into them explicitly. The changes weren't applied when in typeahead mode. Fixes #14274.
1 parent 141afcf commit 4a647a5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,18 @@ describe('Key managers', () => {
664664
expect(keyManager.activeItem).toBe(itemList.items[1]);
665665
}));
666666

667+
it('should not move focus if a modifier, that is not allowed, is pressed', fakeAsync(() => {
668+
const tEvent = createKeyboardEvent('keydown', 84, undefined, 't');
669+
Object.defineProperty(tEvent, 'ctrlKey', {get: () => true});
670+
671+
expect(keyManager.activeItem).toBeFalsy();
672+
673+
keyManager.onKeydown(tEvent); // types "t"
674+
tick(debounceInterval);
675+
676+
expect(keyManager.activeItem).toBeFalsy();
677+
}));
678+
667679
it('should focus the first item that starts with sequence of letters', fakeAsync(() => {
668680
keyManager.onKeydown(createKeyboardEvent('keydown', 84, undefined, 't')); // types "t"
669681
keyManager.onKeydown(createKeyboardEvent('keydown', 72, undefined, 'h')); // types "h"

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,12 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
246246
default:
247247
// Attempt to use the `event.key` which also maps it to the user's keyboard language,
248248
// otherwise fall back to resolving alphanumeric characters via the keyCode.
249-
if (event.key && event.key.length === 1) {
250-
this._letterKeyStream.next(event.key.toLocaleUpperCase());
251-
} else if ((keyCode >= A && keyCode <= Z) || (keyCode >= ZERO && keyCode <= NINE)) {
252-
this._letterKeyStream.next(String.fromCharCode(keyCode));
249+
if (isModifierAllowed) {
250+
if (event.key && event.key.length === 1) {
251+
this._letterKeyStream.next(event.key.toLocaleUpperCase());
252+
} else if ((keyCode >= A && keyCode <= Z) || (keyCode >= ZERO && keyCode <= NINE)) {
253+
this._letterKeyStream.next(String.fromCharCode(keyCode));
254+
}
253255
}
254256

255257
// Note that we return here, in order to avoid preventing

0 commit comments

Comments
 (0)