Skip to content

Commit 9b501c9

Browse files
committed
fix(cdk/a11y): revert Typeahead to use event.keycode; other components depend on it now
1 parent 7c03581 commit 9b501c9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {A, NINE, Z, ZERO} from '@angular/cdk/keycodes';
910
import {Subject, Observable} from 'rxjs';
1011
import {debounceTime, filter, map, tap} from 'rxjs/operators';
1112

@@ -74,8 +75,14 @@ export class Typeahead<T extends TypeaheadItem> {
7475
}
7576

7677
handleKey(event: KeyboardEvent): void {
77-
if (event.key.length === 1) {
78+
const keyCode = event.keyCode;
79+
80+
// Attempt to use the `event.key` which also maps it to the user's keyboard language,
81+
// otherwise fall back to resolving alphanumeric characters via the keyCode.
82+
if (event.key && event.key.length === 1) {
7883
this._letterKeyStream.next(event.key.toLocaleUpperCase());
84+
} else if ((keyCode >= A && keyCode <= Z) || (keyCode >= ZERO && keyCode <= NINE)) {
85+
this._letterKeyStream.next(String.fromCharCode(keyCode));
7986
}
8087
}
8188

0 commit comments

Comments
 (0)