* Handles keyboard events for the menu item, specifically either triggering the user defined * callback or opening/closing the current menu based on whether the left or right arrow key was * pressed. * @param event the keyboard event to handle
(event: KeyboardEvent)
| 199 | * @param event the keyboard event to handle |
| 200 | */ |
| 201 | _onKeydown(event: KeyboardEvent) { |
| 202 | switch (event.keyCode) { |
| 203 | case SPACE: |
| 204 | case ENTER: |
| 205 | // Skip events that will trigger clicks so the handler doesn't get triggered twice. |
| 206 | if (!hasModifierKey(event) && !eventDispatchesNativeClick(this._elementRef, event)) { |
| 207 | const nodeName = this._elementRef.nativeElement.nodeName; |
| 208 | |
| 209 | // Avoid repeat events on non-native elements (see #30250). Note that we don't do this |
| 210 | // on the native elements so we don't interfere with their behavior (see #26296). |
| 211 | if (nodeName !== 'A' && nodeName !== 'BUTTON') { |
| 212 | event.preventDefault(); |
| 213 | } |
| 214 | |
| 215 | this.trigger({keepOpen: event.keyCode === SPACE && !this.closeOnSpacebarTrigger}); |
| 216 | } |
| 217 | break; |
| 218 | |
| 219 | case RIGHT_ARROW: |
| 220 | if (!hasModifierKey(event)) { |
| 221 | if (this._parentMenu && this._isParentVertical()) { |
| 222 | if (this._dir?.value !== 'rtl') { |
| 223 | this._forwardArrowPressed(event); |
| 224 | } else { |
| 225 | this._backArrowPressed(event); |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | break; |
| 230 | |
| 231 | case LEFT_ARROW: |
| 232 | if (!hasModifierKey(event)) { |
| 233 | if (this._parentMenu && this._isParentVertical()) { |
| 234 | if (this._dir?.value !== 'rtl') { |
| 235 | this._backArrowPressed(event); |
| 236 | } else { |
| 237 | this._forwardArrowPressed(event); |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | break; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /** Whether this menu item is standalone or within a menu or menu bar. */ |
| 246 | private _isStandaloneItem() { |
nothing calls this directly
no test coverage detected