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

Method _handleKeydown

src/material/list/selection-list.ts:365–400  ·  view source on GitHub ↗

Handles keydown events within the list.

(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

363
364 /** Handles keydown events within the list. */
365 _handleKeydown(event: KeyboardEvent) {
366 const activeItem = this._keyManager.activeItem;
367
368 if (activeItem && (event.keyCode === DOWN_ARROW || event.keyCode === UP_ARROW)) {
369 const focusedElement = _getFocusedElementPierceShadowDom();
370 const isOptionFocused = this._items
371 .toArray()
372 .some(item => item._elementRef.nativeElement === focusedElement);
373 if (!isOptionFocused) {
374 event.preventDefault();
375 activeItem.focus();
376 return;
377 }
378 }
379
380 if (
381 (event.keyCode === ENTER || event.keyCode === SPACE) &&
382 !this._keyManager.isTyping() &&
383 activeItem &&
384 !activeItem.disabled
385 ) {
386 event.preventDefault();
387 activeItem._toggleOnInteraction();
388 } else if (
389 event.keyCode === A &&
390 this.multiple &&
391 !this._keyManager.isTyping() &&
392 hasModifierKey(event, 'ctrlKey', 'metaKey')
393 ) {
394 const shouldSelect = this.options.some(option => !option.disabled && !option.selected);
395 event.preventDefault();
396 this._emitChangeEvent(this._setAllOptionsSelected(shouldSelect, true));
397 } else {
398 this._keyManager.onKeydown(event);
399 }
400 }
401
402 /** Handles focusout events within the list. */
403 private _handleFocusout = () => {

Callers

nothing calls this directly

Calls 8

_emitChangeEventMethod · 0.95
hasModifierKeyFunction · 0.90
focusMethod · 0.65
onKeydownMethod · 0.65
isTypingMethod · 0.45
_toggleOnInteractionMethod · 0.45

Tested by

no test coverage detected