MCPcopy Index your code
hub / github.com/angular/components / _toggleOnKeydown

Method _toggleOnKeydown

src/cdk/menu/menu-trigger.ts:163–208  ·  view source on GitHub ↗

* Handles keyboard events for the menu item. * @param event The keyboard event to handle

(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

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() {

Callers

nothing calls this directly

Calls 6

toggleMethod · 0.95
openMethod · 0.95
hasModifierKeyFunction · 0.90
focusLastItemMethod · 0.80
focusFirstItemMethod · 0.65

Tested by

no test coverage detected