Skip to content

Commit 903c04a

Browse files
henetirikiLouw Swart
authored andcommitted
feat(expansion): add accordion expand/collapse all (#6929)
Implements review feedback: * missing return type * updated JS Doc * internal-use only underscore * subscription in dedicated function * decoupled event handling from Material implementaion Closes #6929
1 parent 258e83c commit 903c04a

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

src/cdk/accordion/accordion-item.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ export class CdkAccordionItem implements OnDestroy {
7272
private _changeDetectorRef: ChangeDetectorRef,
7373
protected _expansionDispatcher: UniqueSelectionDispatcher) {
7474
this._removeUniqueSelectionListener =
75-
_expansionDispatcher.listen((id: string, accordionId: string) => {
76-
if (this.accordion && !this.accordion.multi &&
77-
this.accordion.id === accordionId && this.id !== id) {
78-
this.expanded = false;
79-
}
80-
});
75+
_expansionDispatcher.listen((id: string, accordionId: string) => {
76+
if (this.accordion && !this.accordion.multi &&
77+
this.accordion.id === accordionId && this.id !== id) {
78+
this.expanded = false;
79+
}
80+
});
8181
}
8282

8383
/** Emits an event for the accordion item being destroyed. */

src/demo-app/expansion/expansion-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {MatAccordion} from '@angular/material';
77
styleUrls: ['expansion-demo.css'],
88
templateUrl: 'expansion-demo.html',
99
encapsulation: ViewEncapsulation.None,
10-
preserveWhitespaces: true,
10+
preserveWhitespaces: false,
1111
})
1212
export class ExpansionDemo {
1313
@ViewChild(MatAccordion) accordion: MatAccordion;

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ import {EXPANSION_PANEL_ANIMATION_TIMING, MatExpansionPanel} from './expansion-p
8383
})
8484
export class MatExpansionPanelHeader implements OnDestroy {
8585
private _parentChangeSubscription = Subscription.EMPTY;
86-
private _expandCollapseAllSubscription = Subscription.EMPTY;
8786

8887
constructor(
8988
renderer: Renderer2,
@@ -102,17 +101,6 @@ export class MatExpansionPanelHeader implements OnDestroy {
102101
.subscribe(() => this._changeDetectorRef.markForCheck());
103102

104103
_focusMonitor.monitor(_element.nativeElement, renderer, false);
105-
106-
// When a panel is hosted in an accordion, subscribe to the expand/collapse subject
107-
if (this.panel.accordion) {
108-
this._expandCollapseAllSubscription =
109-
this.panel.accordion.expandCollapseAllSubject.subscribe((expanded: boolean) => {
110-
// Only toggle if current state is not the intended state
111-
if (!!this._isExpanded() !== expanded) {
112-
this._toggle();
113-
}
114-
});
115-
}
116104
}
117105

118106
/** Height of the header while the panel is expanded. */
@@ -164,7 +152,6 @@ export class MatExpansionPanelHeader implements OnDestroy {
164152

165153
ngOnDestroy() {
166154
this._parentChangeSubscription.unsubscribe();
167-
this._expandCollapseAllSubscription.unsubscribe();
168155
this._focusMonitor.stopMonitoring(this._element.nativeElement);
169156
}
170157
}

0 commit comments

Comments
 (0)