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

Method onFocusOut

src/aria/private/menu/menu.ts:333–361  ·  view source on GitHub ↗

Handles the focusout event for the menu.

(event: FocusEvent)

Source from the content-addressed store, hash-verified

331
332 /** Handles the focusout event for the menu. */
333 onFocusOut(event: FocusEvent) {
334 const parent = this.inputs.parent();
335 const parentEl = parent?.inputs.element();
336 const relatedTarget = event.relatedTarget as Node | null;
337
338 if (!relatedTarget) {
339 this.isFocused.set(false);
340 this.inputs.parent()?.close({refocus: true});
341 }
342
343 if (parent instanceof MenuItemPattern) {
344 const grandparent = parent.inputs.parent();
345 const siblings = grandparent?.inputs.items().filter(i => i !== parent);
346 const item = siblings?.find(i => i.element()?.contains(relatedTarget));
347
348 if (item) {
349 return;
350 }
351 }
352
353 if (
354 this.visible() &&
355 !parentEl?.contains(relatedTarget) &&
356 !this.inputs.element()?.contains(relatedTarget)
357 ) {
358 this.isFocused.set(false);
359 this.inputs.parent()?.close();
360 }
361 }
362
363 /** Focuses the previous menu item. */
364 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