* Handles keyboard events for the menu item. * @param event The keyboard event to handle
(event: KeyboardEvent)
| 161 | * @param event The keyboard event to handle |
| 162 | */ |
| 163 | _toggleOnKeydown(event: KeyboardEvent) { |
| 164 | const isParentVertical = this._parentMenu?.orientation === 'vertical'; |
| 165 | switch (event.keyCode) { |
| 166 | case SPACE: |
| 167 | case ENTER: |
| 168 | // Skip events that will trigger clicks so the handler doesn't get triggered twice. |
| 169 | if (!hasModifierKey(event) && !eventDispatchesNativeClick(this._elementRef, event)) { |
| 170 | this.toggle(); |
| 171 | this.childMenu?.focusFirstItem('keyboard'); |
| 172 | } |
| 173 | break; |
| 174 | |
| 175 | case RIGHT_ARROW: |
| 176 | if (!hasModifierKey(event)) { |
| 177 | if (this._parentMenu && isParentVertical && this._directionality?.value !== 'rtl') { |
| 178 | event.preventDefault(); |
| 179 | this.open(); |
| 180 | this.childMenu?.focusFirstItem('keyboard'); |
| 181 | } |
| 182 | } |
| 183 | break; |
| 184 | |
| 185 | case LEFT_ARROW: |
| 186 | if (!hasModifierKey(event)) { |
| 187 | if (this._parentMenu && isParentVertical && this._directionality?.value === 'rtl') { |
| 188 | event.preventDefault(); |
| 189 | this.open(); |
| 190 | this.childMenu?.focusFirstItem('keyboard'); |
| 191 | } |
| 192 | } |
| 193 | break; |
| 194 | |
| 195 | case DOWN_ARROW: |
| 196 | case UP_ARROW: |
| 197 | if (!hasModifierKey(event)) { |
| 198 | if (!isParentVertical) { |
| 199 | event.preventDefault(); |
| 200 | this.open(); |
| 201 | event.keyCode === DOWN_ARROW |
| 202 | ? this.childMenu?.focusFirstItem('keyboard') |
| 203 | : this.childMenu?.focusLastItem('keyboard'); |
| 204 | } |
| 205 | } |
| 206 | break; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /** Handles clicks on the menu trigger. */ |
| 211 | _handleClick() { |
nothing calls this directly
no test coverage detected