Add overlay info to Vaadin Overlay Closed event.
Describe your motivation
vaadin-overlay-open event has the overlay itself in detail, which can be accessible via const { overlay } = (e as CustomEvent).detail;. However, the same info is not present for vaadin-overlay-closed event.
This is problematic for us because we use an internal array to keep track of which overlays are opened. We know which overlay is opened but we do not know when it is closed. We have a single event listener that is added to document.body, so we cannot possibly know target overlays.
Describe the solution you'd like
It would be nice to have the same information in all events that are dispatched from vaadin-overlay-mixin, such as vaadin-overlay-closed, vaadin-overlay-closing, and others.
Describe alternatives you've considered
A possible solution for this would be registering an event listener when the open event is invoked; however, such a solution may create a memory leak and hanging events if not properly handled.
Additional context
No response
It looks like vaadin-overlay-closed is not fired on the document, so how are you using it with a single listener? Currently you need to add the listener to the overlay element itself, in which case event.target is the overlay.
If we want to support adding single a listener for the event, then we actually need to fire it on the document body first. As that would report the document as event.target that would then also require providing the overlay in the event details.
What would be a good way of tracking opened/closed overlays?
Overlay open works as follows, and the detail has the overlay instance
document.body.addEventListener('vaadin-overlay-open', this.overlayListener);
But no equivalent for the closing/closed events. vaadin-overlay-close and vaadin-overlay-closed are not fired.
There is no good way at the moment. I was mostly clarifying that just adding the overlay to the event's details, which is currently the subject of this issue, will not be sufficient as the event is not fired on the document anyway.
We could fire this event on the document but some components where it matters most already have closed event.
Any updates on this? Copilot will try to workaround it for the moment.
Related issues https://github.com/vaadin/copilot-internal/issues/6682 https://github.com/vaadin/copilot-internal/issues/7222