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

Method onFocusOut

src/aria/private/menu/menu.ts:330–358  ·  view source on GitHub ↗

Handles the focusout event for the menu.

(event: FocusEvent)

Source from the content-addressed store, hash-verified

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