Skip to content

Commit

Permalink
fix(nav): work corretly inside components with OnPush (#3934)
Browse files Browse the repository at this point in the history
A regression introduced with animations.
We already have all tests in place that cover the use case in the issue if we mark `ngbNavOutlet` with `OnPush` itself.

Fixes #3930
  • Loading branch information
maxokorokov committed Jan 8, 2021
1 parent 6790a3e commit 038e89a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/nav/nav-outlet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Directive,
Expand Down Expand Up @@ -42,6 +43,7 @@ export class NgbNavPane {
selector: '[ngbNavOutlet]',
host: {'[class.tab-content]': 'true'},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<ng-template ngFor let-item [ngForOf]="nav.items">
<div ngbNavPane *ngIf="item.isPanelInDom() || isPanelTransitioning(item)" [item]="item" [nav]="nav" [role]="paneRole">
Expand Down Expand Up @@ -88,9 +90,12 @@ export class NgbNavOutlet implements AfterViewInit {
if (this._activePane) {
ngbRunTransition(this._activePane.elRef.nativeElement, ngbNavFadeOutTransition, options).subscribe(() => {
const activeItem = this._activePane ?.item;

this._activePane = this._getPaneForItem(nextItem);

// mark for check when transition finishes as outlet or parent containers might be OnPush
// without this the panes that have "faded out" will stay in DOM
this._cd.markForCheck();

// fading in
if (this._activePane) {
const fadeInTransition = this.nav.animation ? ngbNavFadeInTransition : ngbNavFadeInNoReflowTransition;
Expand Down

0 comments on commit 038e89a

Please sign in to comment.