Handles keyboard events while the select is closed.
(event: KeyboardEvent)
| 900 | |
| 901 | /** Handles keyboard events while the select is closed. */ |
| 902 | private _handleClosedKeydown(event: KeyboardEvent): void { |
| 903 | const keyCode = event.keyCode; |
| 904 | const isArrowKey = |
| 905 | keyCode === DOWN_ARROW || |
| 906 | keyCode === UP_ARROW || |
| 907 | keyCode === LEFT_ARROW || |
| 908 | keyCode === RIGHT_ARROW; |
| 909 | const isOpenKey = keyCode === ENTER || keyCode === SPACE; |
| 910 | const manager = this._keyManager; |
| 911 | |
| 912 | // Open the select on ALT + arrow key to match the native <select> |
| 913 | if ( |
| 914 | (!manager.isTyping() && isOpenKey && !hasModifierKey(event)) || |
| 915 | ((this.multiple || event.altKey) && isArrowKey) |
| 916 | ) { |
| 917 | event.preventDefault(); // prevents the page from scrolling down when pressing space |
| 918 | this.open(); |
| 919 | } else if (!this.multiple) { |
| 920 | const previouslySelectedOption = this.selected; |
| 921 | manager.onKeydown(event); |
| 922 | const selectedOption = this.selected; |
| 923 | |
| 924 | // Since the value has changed, we need to announce it ourselves. |
| 925 | if (selectedOption && previouslySelectedOption !== selectedOption) { |
| 926 | // We set a duration on the live announcement, because we want the live element to be |
| 927 | // cleared after a while so that users can't navigate to it using the arrow keys. |
| 928 | this._liveAnnouncer.announce((selectedOption as MatOption).viewValue, 10000); |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | /** Handles keyboard events when the selected is open. */ |
| 934 | private _handleOpenKeydown(event: KeyboardEvent): void { |
no test coverage detected