Skip to content

Commit 68d09dd

Browse files
crisbetoandrewseguin
authored andcommitted
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. (cherry picked from commit 0faba6e)
1 parent fc6fcbb commit 68d09dd

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
@@ -105,13 +105,14 @@ export class OverlayRef implements PortalOutlet, OverlayReference {
105105
* @returns The portal attachment result.
106106
*/
107107
attach(portal: Portal<any>): any {
108-
let attachResult = this._portalOutlet.attach(portal);
109-
110-
// Update the pane element with the given configuration.
108+
// Insert the host into the DOM before attaching the portal, otherwise
109+
// the animations module will skip animations on repeat attachments.
111110
if (!this._host.parentElement && this._previousHostParent) {
112111
this._previousHostParent.appendChild(this._host);
113112
}
114113

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

0 commit comments

Comments
 (0)