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