-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat(accordion): add animations #3766
feat(accordion): add animations #3766
Conversation
4505ab1
to
ee3e15f
Compare
Codecov Report
@@ Coverage Diff @@
## animations #3766 +/- ##
==============================================
+ Coverage 91.78% 91.82% +0.04%
==============================================
Files 107 107
Lines 3127 3145 +18
Branches 565 566 +1
==============================================
+ Hits 2870 2888 +18
Misses 189 189
Partials 68 68
Continue to review full report at Codecov.
|
ee3e15f
to
a3a11bf
Compare
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.
Hey, @fbasso!
Thanks, this is shorter than before! Left some comments.
- first let's agree on the event API, I have my thoughts in the comment below
- add tests for collapsing events with
animations = false
- check the payload of those events in tests
- I think we can remove
zone.onStable
and all doublefixture.detectChanges()
from tests - don't run
detectChanges()
N
times forN
panels - Either remove the fix for the
ngbRunTransition
or add tests
Cheers,
Max
src/accordion/accordion.ts
Outdated
/** | ||
* If `true`, accordion will be animated. | ||
*/ | ||
@Input() animation = false; |
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.
Please remove = false
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.
This is still not fixed
d0f666b
to
45a0535
Compare
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.
Hey, @fbasso!
LGTM for the code!
The comments I have mostly test- and documentation-related.
I guess that would be the last batch:
- Please check
shown/hidden
is called in the tests (you're still not doing it when animations enabled) - Please remove
animation = false
in theNgbAccordion
(you forgot to do it form the last review) - Please add comments in the code for "tricky" parts (ex. why do we need change detection and why we restart transition even thought it might already be running)
- some other minor comments.
src/accordion/accordion.spec.ts
Outdated
reduceMotion = true; | ||
onShown = (panelId) => panelId; | ||
onHidden = (panelId) => panelId; | ||
onFirstPanelShown = () => {}; |
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.
- you're not using this in ANY tests, please add checks that these callbacks are actually called
- you could have 1 function and just check what id it is called with:
onPanelShown = () = {};
(shown)="onPanelShown('one')"
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.
Finally, I need only the check on panel one, so I'll use it without parameter.
src/accordion/accordion.spec.ts
Outdated
|
||
// Select the first tab -> change event | ||
getButton(fixture.nativeElement, 0).click(); | ||
fixture.detectChanges(); | ||
expect(fixture.componentInstance.changeCallback) | ||
.toHaveBeenCalledWith(jasmine.objectContaining({panelId: 'one', nextState: true})); | ||
expect(fixture.componentInstance.shownCallback).toHaveBeenCalledWith('one'); | ||
expect(fixture.componentInstance.panelShownCallback).toHaveBeenCalled(); |
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.
could we check with .toHaveBeenCalledWith(undefined)
instead?
src/accordion/accordion.spec.ts
Outdated
|
||
// Select the first tab again -> change event | ||
getButton(fixture.nativeElement, 0).click(); | ||
fixture.detectChanges(); | ||
expect(fixture.componentInstance.changeCallback) | ||
.toHaveBeenCalledWith(jasmine.objectContaining({panelId: 'one', nextState: false})); | ||
expect(fixture.componentInstance.hiddenCallback).toHaveBeenCalledWith('one'); | ||
expect(fixture.componentInstance.panelHiddenCallback).toHaveBeenCalled(); |
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.
could we check with .toHaveBeenCalledWith(undefined)
instead?
src/accordion/accordion.spec.ts
Outdated
@@ -552,25 +555,37 @@ describe('ngb-accordion', () => { | |||
expect(panelContents.length).toBe(3); | |||
}); | |||
|
|||
it('should emit panel change event when toggling panels', () => { | |||
it('should emit panel events when toggling panels', () => { | |||
const fixture = TestBed.createComponent(TestComponent); | |||
fixture.detectChanges(); | |||
|
|||
fixture.componentInstance.changeCallback = () => {}; |
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.
please remove all these:
fuxture.componentInstance.xxx = () => {}
They're already declared in the TestComponent
, no need to re-declare them
src/accordion/accordion.spec.ts
Outdated
const onHiddenSpy = spyOn(fixture.componentInstance, 'onHidden'); | ||
|
||
// First we're going to collapse, then expand | ||
let opened = true; |
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.
why have this flag? it's not used anywhere
src/accordion/accordion.ts
Outdated
/** | ||
* If `true`, accordion will be animated. | ||
*/ | ||
@Input() animation = false; |
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.
This is still not fixed
src/accordion/accordion.ts
Outdated
@@ -216,7 +239,18 @@ export class NgbAccordion implements AfterContentChecked { | |||
*/ | |||
@Output() panelChange = new EventEmitter<NgbPanelChangeEvent>(); | |||
|
|||
constructor(config: NgbAccordionConfig) { | |||
/** | |||
* An event emitted when a panel is shown, after the transition. The payload is the panel id. |
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.
Could we be more specific, please ? meaning that "when the panel is shown" is not very clear...
Maybe An event emitted when the expanding animation is finished on the panel
?
src/accordion/accordion.ts
Outdated
@Output() shown = new EventEmitter<string>(); | ||
|
||
/** | ||
* An event emitted when a panel is hidden, after the transition. The payload is the panel id. |
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.
Same here, but collapsing animation
. Would also be nice to precise, if DOM content is expected to be removed at this point or not.
45a0535
to
7683ef3
Compare
I push again with all the requested changes (I hope I didn't forget anything !). Unfortunately, I had to change the accordion code again. This is due to some failing tests on what classes are expected (after the ngbTransition refactor with the startFn): classes managed by the transitions shouldn't be managed by bindings. I'm not very happy with the code produced, but this is due to the initial code which would require a BIG refactor, probably in order to avoid
I did not want to include this refactor, otherwise the review would be much harder. |
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.
Hey, @fbasso, just will put a quick summary here.
In the latest version:
- demos are not working
- by doing
_runTransitions
in theafterContentCheked
we're triggering it on each CD. On top of this the first thing_runTrainsitions
is doing is actuallydetectChanges()
. I think we should find a way to trigger transitions the same way we're doing for the collapse → only on binding changes, manual clicks or imperative toggles
7683ef3
to
fe1a0fd
Compare
Last changes pushed ! I finally managed to eliminate the change detection change on @maxokorokov , @benouat, don't hesitate to share if you have other ideas. |
156e642
to
388b90c
Compare
388b90c
to
71ebf39
Compare
Cherry picked from #2817, with some changes.
The key points are:
detectChanges
have been added in the previous tests, because of thechangeDetector.detectChanges()
required in_runTransition
,