Skip to content

Commit

Permalink
chore(expansion-panel): switch to OnPush change detection
Browse files Browse the repository at this point in the history
* Switches the expansion panel to `OnPush` change detection.
* Fixes the open animation not triggering on the body element.

Relates to angular#5035.
  • Loading branch information
crisbeto committed Jul 6, 2017
1 parent ac3e21a commit 50aa7ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/lib/expansion/accordion-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Output, EventEmitter, Input, Injectable, OnDestroy, Optional} from '@angular/core';
import {
Output,
EventEmitter,
Input,
Injectable,
OnDestroy,
Optional,
ChangeDetectorRef,
} from '@angular/core';
import {UniqueSelectionDispatcher} from '../core';
import {CdkAccordion} from './accordion';

Expand Down Expand Up @@ -44,6 +52,8 @@ export class AccordionItem implements OnDestroy {
} else {
this.closed.emit();
}

this._changeDetectorRef.markForCheck();
}
}
private _expanded: boolean;
Expand All @@ -52,6 +62,7 @@ export class AccordionItem implements OnDestroy {
private _removeUniqueSelectionListener: () => void = () => {};

constructor(@Optional() public accordion: CdkAccordion,
private _changeDetectorRef: ChangeDetectorRef,
protected _expansionDispatcher: UniqueSelectionDispatcher) {
this._removeUniqueSelectionListener =
_expansionDispatcher.listen((id: string, accordionId: string) => {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/expansion/expansion-panel-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Directive,
Host,
ViewEncapsulation,
ChangeDetectionStrategy,
} from '@angular/core';
import {
trigger,
Expand All @@ -36,6 +37,7 @@ import {MdExpansionPanel, EXPANSION_PANEL_ANIMATION_TIMING} from './expansion-pa
styleUrls: ['./expansion-panel-header.css'],
templateUrl: './expansion-panel-header.html',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'class': 'mat-expansion-panel-header',
'role': 'button',
Expand Down
6 changes: 5 additions & 1 deletion src/lib/expansion/expansion-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
ViewEncapsulation,
Optional,
forwardRef,
ChangeDetectionStrategy,
ChangeDetectorRef,
} from '@angular/core';
import {
trigger,
Expand Down Expand Up @@ -47,6 +49,7 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,
selector: 'md-expansion-panel, mat-expansion-panel',
templateUrl: './expansion-panel.html',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'class': 'mat-expansion-panel',
'[class.mat-expanded]': 'expanded',
Expand Down Expand Up @@ -75,8 +78,9 @@ export class MdExpansionPanel extends AccordionItem {
@Input() hideToggle: boolean = false;

constructor(@Optional() @Host() accordion: MdAccordion,
_changeDetectorRef: ChangeDetectorRef,
_uniqueSelectionDispatcher: UniqueSelectionDispatcher) {
super(accordion, _uniqueSelectionDispatcher);
super(accordion, _changeDetectorRef, _uniqueSelectionDispatcher);
this.accordion = accordion;
}

Expand Down

0 comments on commit 50aa7ce

Please sign in to comment.