Handles the focusout event for the menu.
(event: FocusEvent)
| 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() { |