Called when the user presses keydown on the listbox.
(event: KeyboardEvent)
| 715 | |
| 716 | /** Called when the user presses keydown on the listbox. */ |
| 717 | protected _handleKeydown(event: KeyboardEvent) { |
| 718 | if (this.disabled) { |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | const {keyCode} = event; |
| 723 | const previousActiveIndex = this.listKeyManager.activeItemIndex; |
| 724 | const ctrlKeys = ['ctrlKey', 'metaKey'] as const; |
| 725 | |
| 726 | if (this.multiple && keyCode === A && hasModifierKey(event, ...ctrlKeys)) { |
| 727 | // Toggle all options off if they're all selected, otherwise toggle them all on. |
| 728 | this.triggerRange( |
| 729 | null, |
| 730 | 0, |
| 731 | this.options.length - 1, |
| 732 | this.options.length !== this.value.length, |
| 733 | ); |
| 734 | event.preventDefault(); |
| 735 | return; |
| 736 | } |
| 737 | |
| 738 | if ( |
| 739 | this.multiple && |
| 740 | (keyCode === SPACE || keyCode === ENTER) && |
| 741 | hasModifierKey(event, 'shiftKey') |
| 742 | ) { |
| 743 | if (this.listKeyManager.activeItem && this.listKeyManager.activeItemIndex != null) { |
| 744 | this.triggerRange( |
| 745 | this.listKeyManager.activeItem, |
| 746 | this._getLastTriggeredIndex() ?? this.listKeyManager.activeItemIndex, |
| 747 | this.listKeyManager.activeItemIndex, |
| 748 | !this.listKeyManager.activeItem.isSelected(), |
| 749 | ); |
| 750 | } |
| 751 | event.preventDefault(); |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | if ( |
| 756 | this.multiple && |
| 757 | keyCode === HOME && |
| 758 | hasModifierKey(event, ...ctrlKeys) && |
| 759 | hasModifierKey(event, 'shiftKey') |
| 760 | ) { |
| 761 | const trigger = this.listKeyManager.activeItem; |
| 762 | if (trigger) { |
| 763 | const from = this.listKeyManager.activeItemIndex!; |
| 764 | this.listKeyManager.setFirstItemActive(); |
| 765 | this.triggerRange( |
| 766 | trigger, |
| 767 | from, |
| 768 | this.listKeyManager.activeItemIndex!, |
| 769 | !trigger.isSelected(), |
| 770 | ); |
| 771 | } |
| 772 | event.preventDefault(); |
| 773 | return; |
| 774 | } |
nothing calls this directly
no test coverage detected