Handles keyboard events when the selected is open.
(event: KeyboardEvent)
| 932 | |
| 933 | /** Handles keyboard events when the selected is open. */ |
| 934 | private _handleOpenKeydown(event: KeyboardEvent): void { |
| 935 | const manager = this._keyManager; |
| 936 | const keyCode = event.keyCode; |
| 937 | const isArrowKey = keyCode === DOWN_ARROW || keyCode === UP_ARROW; |
| 938 | const isTyping = manager.isTyping(); |
| 939 | |
| 940 | if (isArrowKey && event.altKey) { |
| 941 | // Close the select on ALT + arrow key to match the native <select> |
| 942 | event.preventDefault(); |
| 943 | this.close(); |
| 944 | // Don't do anything in this case if the user is typing, |
| 945 | // because the typing sequence can include the space key. |
| 946 | } else if ( |
| 947 | !isTyping && |
| 948 | (keyCode === ENTER || keyCode === SPACE) && |
| 949 | manager.activeItem && |
| 950 | !hasModifierKey(event) |
| 951 | ) { |
| 952 | event.preventDefault(); |
| 953 | manager.activeItem._selectViaInteraction(); |
| 954 | } else if (!isTyping && this._multiple && keyCode === A && event.ctrlKey) { |
| 955 | event.preventDefault(); |
| 956 | const hasDeselectedOptions = this.options.some(opt => !opt.disabled && !opt.selected); |
| 957 | |
| 958 | this.options.forEach(option => { |
| 959 | if (!option.disabled) { |
| 960 | hasDeselectedOptions ? option.select() : option.deselect(); |
| 961 | } |
| 962 | }); |
| 963 | } else { |
| 964 | const previouslyFocusedIndex = manager.activeItemIndex; |
| 965 | |
| 966 | manager.onKeydown(event); |
| 967 | |
| 968 | if ( |
| 969 | this._multiple && |
| 970 | isArrowKey && |
| 971 | event.shiftKey && |
| 972 | manager.activeItem && |
| 973 | manager.activeItemIndex !== previouslyFocusedIndex |
| 974 | ) { |
| 975 | manager.activeItem._selectViaInteraction(); |
| 976 | } |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | /** Handles keyboard events coming from the overlay. */ |
| 981 | protected _handleOverlayKeydown(event: KeyboardEvent): void { |
no test coverage detected