Handles custom keyboard events.
(event: KeyboardEvent)
| 444 | |
| 445 | /** Handles custom keyboard events. */ |
| 446 | override _handleKeydown(event: KeyboardEvent) { |
| 447 | const keyCode = event.keyCode; |
| 448 | const activeItem = this._keyManager.activeItem; |
| 449 | |
| 450 | if (keyCode === TAB) { |
| 451 | if ( |
| 452 | this._chipInput?.focused && |
| 453 | hasModifierKey(event, 'shiftKey') && |
| 454 | this._chips.length && |
| 455 | !this._chips.last.disabled |
| 456 | ) { |
| 457 | event.preventDefault(); |
| 458 | |
| 459 | if (activeItem) { |
| 460 | this._keyManager.setActiveItem(activeItem); |
| 461 | } else { |
| 462 | this._focusLastChip(); |
| 463 | } |
| 464 | } else { |
| 465 | // Use the super method here since it doesn't check for the input |
| 466 | // focused state. This allows focus to escape if there's only one |
| 467 | // disabled chip left in the list. |
| 468 | super._allowFocusEscape(); |
| 469 | } |
| 470 | } else if (!this._chipInput?.focused) { |
| 471 | // The up and down arrows are supposed to navigate between the individual rows in the grid. |
| 472 | // We do this by filtering the actions down to the ones that have the same `_isPrimary` |
| 473 | // flag as the active action and moving focus between them ourseles instead of delegating |
| 474 | // to the key manager. For more information, see #29359 and: |
| 475 | // https://www.w3.org/WAI/ARIA/apg/patterns/grid/examples/layout-grids/#ex2_label |
| 476 | if ((keyCode === UP_ARROW || keyCode === DOWN_ARROW) && activeItem) { |
| 477 | const eligibleActions = this._chipActions.filter( |
| 478 | action => action._isPrimary === activeItem._isPrimary && !this._skipPredicate(action), |
| 479 | ); |
| 480 | const currentIndex = eligibleActions.indexOf(activeItem); |
| 481 | const delta = event.keyCode === UP_ARROW ? -1 : 1; |
| 482 | |
| 483 | event.preventDefault(); |
| 484 | if (currentIndex > -1 && this._isValidIndex(currentIndex + delta)) { |
| 485 | this._keyManager.setActiveItem(eligibleActions[currentIndex + delta]); |
| 486 | } |
| 487 | } else { |
| 488 | super._handleKeydown(event); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | this.stateChanges.next(); |
| 493 | } |
| 494 | |
| 495 | protected override _redirectDestroyedChipFocus() { |
| 496 | if (this._lastDestroyedFocusedChipIndex === null) { |
nothing calls this directly
no test coverage detected