Skip to content

Commit

Permalink
fix(cdk/a11y): revert Typeahead to use event.keycode; other component…
Browse files Browse the repository at this point in the history
…s depend on it now
  • Loading branch information
BobobUnicorn committed May 21, 2024
1 parent 7c03581 commit 9b501c9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cdk/a11y/key-manager/typeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

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

Expand Down Expand Up @@ -74,8 +75,14 @@ export class Typeahead<T extends TypeaheadItem> {
}

handleKey(event: KeyboardEvent): void {
if (event.key.length === 1) {
const keyCode = event.keyCode;

// Attempt to use the `event.key` which also maps it to the user's keyboard language,
// otherwise fall back to resolving alphanumeric characters via the keyCode.
if (event.key && event.key.length === 1) {
this._letterKeyStream.next(event.key.toLocaleUpperCase());
} else if ((keyCode >= A && keyCode <= Z) || (keyCode >= ZERO && keyCode <= NINE)) {
this._letterKeyStream.next(String.fromCharCode(keyCode));
}
}

Expand Down

0 comments on commit 9b501c9

Please sign in to comment.