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

Method _handleClosedKeydown

src/material/select/select.ts:904–933  ·  view source on GitHub ↗

Handles keyboard events while the select is closed.

(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

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

Callers 1

_handleKeydownMethod · 0.95

Calls 5

openMethod · 0.95
hasModifierKeyFunction · 0.90
onKeydownMethod · 0.65
isTypingMethod · 0.45
announceMethod · 0.45

Tested by

no test coverage detected