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