Skip to content

Commit c2996a2

Browse files
committed
chore(expansion-panel): switch to OnPush change detection
* Switches the expansion panel to `OnPush` change detection. * Fixes the open animation not triggering on the body element. Relates to #5035.
1 parent ac3e21a commit c2996a2

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/lib/expansion/accordion-item.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Output, EventEmitter, Input, Injectable, OnDestroy, Optional} from '@angular/core';
9+
import {
10+
Output,
11+
EventEmitter,
12+
Input,
13+
Injectable,
14+
OnDestroy,
15+
Optional,
16+
ChangeDetectorRef,
17+
} from '@angular/core';
1018
import {UniqueSelectionDispatcher} from '../core';
1119
import {CdkAccordion} from './accordion';
1220

@@ -44,6 +52,10 @@ export class AccordionItem implements OnDestroy {
4452
} else {
4553
this.closed.emit();
4654
}
55+
56+
// Ensures that the animation will run when the value is set outside of an `@Input`.
57+
// This includes cases like the open, close and toggle methods.
58+
this._changeDetectorRef.markForCheck();
4759
}
4860
}
4961
private _expanded: boolean;
@@ -52,6 +64,7 @@ export class AccordionItem implements OnDestroy {
5264
private _removeUniqueSelectionListener: () => void = () => {};
5365

5466
constructor(@Optional() public accordion: CdkAccordion,
67+
private _changeDetectorRef: ChangeDetectorRef,
5568
protected _expansionDispatcher: UniqueSelectionDispatcher) {
5669
this._removeUniqueSelectionListener =
5770
_expansionDispatcher.listen((id: string, accordionId: string) => {

src/lib/expansion/expansion-panel-header.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Directive,
1212
Host,
1313
ViewEncapsulation,
14+
ChangeDetectionStrategy,
1415
} from '@angular/core';
1516
import {
1617
trigger,
@@ -36,6 +37,7 @@ import {MdExpansionPanel, EXPANSION_PANEL_ANIMATION_TIMING} from './expansion-pa
3637
styleUrls: ['./expansion-panel-header.css'],
3738
templateUrl: './expansion-panel-header.html',
3839
encapsulation: ViewEncapsulation.None,
40+
changeDetection: ChangeDetectionStrategy.OnPush,
3941
host: {
4042
'class': 'mat-expansion-panel-header',
4143
'role': 'button',

src/lib/expansion/expansion-panel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
ViewEncapsulation,
1515
Optional,
1616
forwardRef,
17+
ChangeDetectionStrategy,
18+
ChangeDetectorRef,
1719
} from '@angular/core';
1820
import {
1921
trigger,
@@ -47,6 +49,7 @@ export const EXPANSION_PANEL_ANIMATION_TIMING = '225ms cubic-bezier(0.4,0.0,0.2,
4749
selector: 'md-expansion-panel, mat-expansion-panel',
4850
templateUrl: './expansion-panel.html',
4951
encapsulation: ViewEncapsulation.None,
52+
changeDetection: ChangeDetectionStrategy.OnPush,
5053
host: {
5154
'class': 'mat-expansion-panel',
5255
'[class.mat-expanded]': 'expanded',
@@ -75,8 +78,9 @@ export class MdExpansionPanel extends AccordionItem {
7578
@Input() hideToggle: boolean = false;
7679

7780
constructor(@Optional() @Host() accordion: MdAccordion,
81+
_changeDetectorRef: ChangeDetectorRef,
7882
_uniqueSelectionDispatcher: UniqueSelectionDispatcher) {
79-
super(accordion, _uniqueSelectionDispatcher);
83+
super(accordion, _changeDetectorRef, _uniqueSelectionDispatcher);
8084
this.accordion = accordion;
8185
}
8286

0 commit comments

Comments
 (0)