Skip to content

Commit 3a52624

Browse files
amcdnlandrewseguin
authored andcommitted
feat(tabs): add animation done event #5238 (#6811)
* feat(tabs): add animation done event #5238 * chore(test): add test * chore(tests): remove fit
1 parent a411382 commit 3a52624

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/lib/tabs/tab-group.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ describe('MatTabGroup', () => {
208208
expect(tabs[1].isActive).toBe(false);
209209
expect(tabs[2].isActive).toBe(true);
210210
});
211+
212+
it('should fire animation done event', fakeAsync(() => {
213+
fixture.detectChanges();
214+
215+
spyOn(fixture.componentInstance, 'animationDone');
216+
let tabLabel = fixture.debugElement.queryAll(By.css('.mat-tab-label'))[1];
217+
tabLabel.nativeElement.click();
218+
fixture.detectChanges();
219+
tick();
220+
221+
expect(fixture.componentInstance.animationDone).toHaveBeenCalled();
222+
}));
211223
});
212224

213225
describe('disable tabs', () => {
@@ -430,6 +442,7 @@ describe('nested MatTabGroup with enabled animations', () => {
430442
[(selectedIndex)]="selectedIndex"
431443
[headerPosition]="headerPosition"
432444
[disableRipple]="disableRipple"
445+
(animationDone)="animationDone()"
433446
(focusChange)="handleFocus($event)"
434447
(selectedTabChange)="handleSelection($event)">
435448
<mat-tab>
@@ -460,6 +473,7 @@ class SimpleTabsTestApp {
460473
handleSelection(event: any) {
461474
this.selectEvent = event;
462475
}
476+
animationDone() { }
463477
}
464478

465479
@Component({

src/lib/tabs/tab-group.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
141141
/** Event emitted when focus has changed within a tab group. */
142142
@Output() focusChange: EventEmitter<MatTabChangeEvent> = new EventEmitter<MatTabChangeEvent>();
143143

144+
/** Event emitted when the body animation has completed */
145+
@Output() animationDone: EventEmitter<void> = new EventEmitter<void>();
146+
144147
/** Event emitted when the tab selection has changed. */
145148
@Output() selectedTabChange: EventEmitter<MatTabChangeEvent> =
146149
new EventEmitter<MatTabChangeEvent>(true);
@@ -280,6 +283,7 @@ export class MatTabGroup extends _MatTabGroupMixinBase implements AfterContentIn
280283
_removeTabBodyWrapperHeight(): void {
281284
this._tabBodyWrapperHeight = this._tabBodyWrapper.nativeElement.clientHeight;
282285
this._tabBodyWrapper.nativeElement.style.height = '';
286+
this.animationDone.emit();
283287
}
284288

285289
/** Handle click events, setting new selected index if appropriate. */

0 commit comments

Comments
 (0)