-
Notifications
You must be signed in to change notification settings - Fork 27.1k
fix(animations): enable shadowElements to leave when their parent does #46459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
dario-piotrowicz
wants to merge
1
commit into
angular:main
from
dario-piotrowicz:animations-shadow-bug
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,13 +5,13 @@ | |
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
| import {animate, animateChild, AnimationPlayer, AUTO_STYLE, group, query, sequence, stagger, state, style, transition, trigger, ɵAnimationGroupPlayer as AnimationGroupPlayer} from '@angular/animations'; | ||
| import {animate, animateChild, AnimationEvent, AnimationPlayer, AUTO_STYLE, group, query, sequence, stagger, state, style, transition, trigger, ɵAnimationGroupPlayer as AnimationGroupPlayer} from '@angular/animations'; | ||
| import {AnimationDriver, ɵAnimationEngine, ɵnormalizeKeyframes as normalizeKeyframes} from '@angular/animations/browser'; | ||
| import {TransitionAnimationPlayer} from '@angular/animations/browser/src/render/transition_animation_engine'; | ||
| import {ENTER_CLASSNAME, LEAVE_CLASSNAME} from '@angular/animations/browser/src/util'; | ||
| import {MockAnimationDriver, MockAnimationPlayer} from '@angular/animations/browser/testing'; | ||
| import {CommonModule} from '@angular/common'; | ||
| import {Component, HostBinding, ViewChild} from '@angular/core'; | ||
| import {Component, HostBinding, ViewChild, ViewEncapsulation} from '@angular/core'; | ||
| import {fakeAsync, flushMicrotasks, TestBed} from '@angular/core/testing'; | ||
| import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; | ||
|
|
||
|
|
@@ -2832,6 +2832,64 @@ describe('animation query tests', function() { | |
| ]); | ||
| })); | ||
|
|
||
| it(`should emulate a leave animation on a child elements when a parent component using shadowDom leaves the DOM`, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| fakeAsync(() => { | ||
| let childLeaveLog = 0; | ||
|
|
||
| @Component({ | ||
| selector: 'ani-host', | ||
| template: `<ani-parent *ngIf="exp"></ani-parent>`, | ||
| }) | ||
| class HostCmp { | ||
| public exp: boolean = false; | ||
| } | ||
|
|
||
| @Component({ | ||
| selector: 'ani-parent', | ||
| encapsulation: ViewEncapsulation.ShadowDom, | ||
| template: ` | ||
| <div @childAnimation (@childAnimation.start)="logChildLeave($event)"></div> | ||
| `, | ||
| animations: [ | ||
| trigger( | ||
| 'childAnimation', | ||
| [ | ||
| transition(':leave', []), | ||
| ]), | ||
| ] | ||
| }) | ||
| class ParentCmp { | ||
| logChildLeave(event: AnimationEvent) { | ||
| if (event.toState === 'void') { | ||
| childLeaveLog++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| TestBed.configureTestingModule({declarations: [ParentCmp, HostCmp]}); | ||
|
|
||
| const fixture = TestBed.createComponent(HostCmp); | ||
| const cmp = fixture.componentInstance; | ||
|
|
||
| const updateExpAndFlush = (value: boolean) => { | ||
| cmp.exp = value; | ||
| fixture.detectChanges(); | ||
| flushMicrotasks(); | ||
| }; | ||
|
|
||
| updateExpAndFlush(true); | ||
| expect(childLeaveLog).toEqual(0); | ||
|
|
||
| updateExpAndFlush(false); | ||
| expect(childLeaveLog).toEqual(1); | ||
|
|
||
| updateExpAndFlush(true); | ||
| expect(childLeaveLog).toEqual(1); | ||
|
|
||
| updateExpAndFlush(false); | ||
| expect(childLeaveLog).toEqual(2); | ||
| })); | ||
|
|
||
| it('should build, but not run sub triggers when a parent animation is scheduled', () => { | ||
| @Component({ | ||
| selector: 'parent-cmp', | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of an edge case, but this won't handle nested shadow roots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah, you're totally right, as I mentioned in the PR's description I already saw that querying does not work with shadowDom, I'll look into improving the
queryfunction to also take shadowDom into account, so I think that should fix the case you're mentioningSo if you prefer I extend this PR with the query improvement or we can try to merge it now and look into the querying issue as a separate task, please let me know whatever works best for you 🙂
(I think I'd go with extending the
queryfunction as a separate PR, but I'll need to make extra sure that this piece of code is cleaned up)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with merging it as it is, but I wanted to flag it as a potential issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome thanks 🙂 , I'll make sure to address it! 👍