MCPcopy Create free account
hub / github.com/angular/components / _handleOpenKeydown

Method _handleOpenKeydown

src/material/select/select.ts:936–980  ·  view source on GitHub ↗

Handles keyboard events when the selected is open.

(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

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