Skip to content

Commit 0faba6e

Browse files
authored
fix(cdk/overlay): animations interrupted on repeat insertions (#24815)
When an overlay is detached, we remove it from the change detection tree and the DOM, but we don't destroy it completely so that it can be re-attached. Re-attachment is the same process, but in reverse: we re-add the element to the DOM and the change detection tree. The problem is that we were attaching the element to the change detection tree before re-inserting it into the DOM which caused the Angular animations package not to animate the element since it's not in the DOM yet. These changes resolve the issue by attaching the element to the DOM first. Fixes #24749.
1 parent 54cb83e commit 0faba6e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,14 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
106106
* @returns The portal attachment result.
107107
*/
108108
attach(portal: Portal<any>): any {
109-
let attachResult = this._portalOutlet.attach(portal);
110-
111-
// Update the pane element with the given configuration.
109+
// Insert the host into the DOM before attaching the portal, otherwise
110+
// the animations module will skip animations on repeat attachments.
112111
if (!this._host.parentElement && this._previousHostParent) {
113112
this._previousHostParent.appendChild(this._host);
114113
}
115114

115+
const attachResult = this._portalOutlet.attach(portal);
116+
116117
if (this._positionStrategy) {
117118
this._positionStrategy.attach(this);
118119
}

0 commit comments

Comments
 (0)