MCPcopy Create free account
hub / github.com/angular/components / onFocusOut

Method onFocusOut

src/aria/private/menu/menu.ts:349–377  ·  view source on GitHub ↗

Handles the focusout event for the menu.

(event: FocusEvent)

Source from the content-addressed store, hash-verified

347
348 /** Handles the focusout event for the menu. */
349 onFocusOut(event: FocusEvent) {
350 const parent = this.inputs.parent();
351 const parentEl = parent?.inputs.element();
352 const relatedTarget = event.relatedTarget as Node | null;
353
354 if (!relatedTarget) {
355 this.isFocused.set(false);
356 this.inputs.parent()?.close({refocus: true});
357 }
358
359 if (parent instanceof MenuItemPattern) {
360 const grandparent = parent.inputs.parent();
361 const siblings = grandparent?.inputs.items().filter(i => i !== parent);
362 const item = siblings?.find(i => i.element()?.contains(relatedTarget));
363
364 if (item) {
365 return;
366 }
367 }
368
369 if (
370 this.visible() &&
371 !parentEl?.contains(relatedTarget) &&
372 !this.inputs.element()?.contains(relatedTarget)
373 ) {
374 this.isFocused.set(false);
375 this.inputs.parent()?.close();
376 }
377 }
378
379 /** Focuses the previous menu item. */
380 prev() {

Callers 1

menu.spec.tsFile · 0.45

Calls 6

parentMethod · 0.80
setMethod · 0.80
visibleMethod · 0.80
elementMethod · 0.45
closeMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected