Skip to content

Commit bbd71c6

Browse files
committed
feat(cdk/a11y): handle typeahead in keydown handler
1 parent 38d2bd5 commit bbd71c6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,21 @@ export class TreeKeyManager<T extends TreeKeyManagerItem> {
243243
break;
244244
}
245245

246+
// Attempt to use the `event.key` which also maps it to the user's keyboard language,
247+
// otherwise fall back to resolving alphanumeric characters via the keyCode.
248+
if (event.key && event.key.length === 1) {
249+
this._letterKeyStream.next(event.key.toLocaleUpperCase());
250+
} else if ((keyCode >= A && keyCode <= Z) || (keyCode >= ZERO && keyCode <= NINE)) {
251+
this._letterKeyStream.next(String.fromCharCode(keyCode));
252+
}
253+
246254
// NB: return here, in order to avoid preventing the default action of non-navigational
247255
// keys or resetting the buffer of pressed letters.
248256
return;
249257
}
250258

259+
// Reset the typeahead since the user has used a navigational key.
260+
this._pressedLetters = [];
251261
event.preventDefault();
252262
}
253263

0 commit comments

Comments
 (0)