Skip to content
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

chore(expansion-panel): switch to OnPush change detection #5549

Merged
merged 1 commit into from
Jul 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 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,10 @@ export class AccordionItem implements OnDestroy {
} else {
this.closed.emit();
}

// Ensures that the animation will run when the value is set outside of an `@Input`.
// This includes cases like the open, close and toggle methods.
this._changeDetectorRef.markForCheck();
}
}
private _expanded: boolean;
Expand All @@ -52,6 +64,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