Skip to content

Commit b77f4bc

Browse files
committed
feat(cdk/a11y): handle typeahead in keydown handler
1 parent 3befe7d commit b77f4bc

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
@@ -247,11 +247,21 @@ export class TreeKeyManager<T extends TreeKeyManagerItem> {
247247
break;
248248
}
249249

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

263+
// Reset the typeahead since the user has used a navigational key.
264+
this._pressedLetters = [];
255265
event.preventDefault();
256266
}
257267

0 commit comments

Comments
 (0)