|
9 | 9 | import {QueryList} from '@angular/core'; |
10 | 10 | import {Subject} from 'rxjs/Subject'; |
11 | 11 | import {Subscription} from 'rxjs/Subscription'; |
12 | | -import {UP_ARROW, DOWN_ARROW, TAB, A, Z} from '@angular/cdk/keycodes'; |
| 12 | +import {UP_ARROW, DOWN_ARROW, TAB, A, Z, ZERO, NINE} from '@angular/cdk/keycodes'; |
13 | 13 | import {RxChain, debounceTime, filter, map, doOperator} from '@angular/cdk/rxjs'; |
14 | 14 |
|
15 | 15 | /** |
@@ -107,17 +107,19 @@ export class ListKeyManager<T extends ListKeyManagerOption> { |
107 | 107 | case UP_ARROW: this.setPreviousItemActive(); break; |
108 | 108 | case TAB: this.tabOut.next(); return; |
109 | 109 | default: |
110 | | - if (event.keyCode >= A && event.keyCode <= Z) { |
111 | | - // Attempt to use the `event.key` which also maps it to the user's keyboard language, |
112 | | - // otherwise fall back to `keyCode` and `fromCharCode` which always resolve to English. |
113 | | - this._letterKeyStream.next(event.key ? |
114 | | - event.key.toLocaleUpperCase() : |
115 | | - String.fromCharCode(event.keyCode)); |
| 110 | + const keyCode = event.keyCode; |
| 111 | + |
| 112 | + // Attempt to use the `event.key` which also maps it to the user's keyboard language, |
| 113 | + // otherwise fall back to resolving alphanumeric characters via the keyCode. |
| 114 | + if (event.key && event.key.length === 1) { |
| 115 | + this._letterKeyStream.next(event.key.toLocaleUpperCase()); |
| 116 | + } else if ((keyCode >= A && keyCode <= Z) || (keyCode >= ZERO && keyCode <= NINE)) { |
| 117 | + this._letterKeyStream.next(String.fromCharCode(keyCode)); |
116 | 118 | } |
117 | 119 |
|
118 | | - // Note that we return here, in order to avoid preventing |
119 | | - // the default action of non-navigational keys. |
120 | | - return; |
| 120 | + // Note that we return here, in order to avoid preventing |
| 121 | + // the default action of non-navigational keys. |
| 122 | + return; |
121 | 123 | } |
122 | 124 |
|
123 | 125 | this._pressedLetters = []; |
|
0 commit comments