MCPcopy Index your code
hub / github.com/angular/components / _handleOpenKeydown

Method _handleOpenKeydown

src/material/select/select.ts:934–978  ·  view source on GitHub ↗

Handles keyboard events when the selected is open.

(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

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 {

Callers 1

_handleKeydownMethod · 0.95

Calls 7

closeMethod · 0.95
hasModifierKeyFunction · 0.90
_selectViaInteractionMethod · 0.80
selectMethod · 0.65
deselectMethod · 0.65
onKeydownMethod · 0.65
isTypingMethod · 0.45

Tested by

no test coverage detected