Skip to content

Commit 4e1d639

Browse files
authored
docs(material/expansion): Update expansion docs & examples (#29244)
1 parent 2c0833c commit 4e1d639

File tree

8 files changed

+64
-78
lines changed

8 files changed

+64
-78
lines changed

src/components-examples/material/expansion/expansion-expand-collapse-all/expansion-expand-collapse-all-example.html

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<div class="example-action-buttons">
2-
<button mat-button (click)="accordion.openAll()">Expand All</button>
3-
<button mat-button (click)="accordion.closeAll()">Collapse All</button>
2+
<button mat-button (click)="accordion().openAll()">Expand All</button>
3+
<button mat-button (click)="accordion().closeAll()">Collapse All</button>
44
</div>
55
<!-- #docregion multi -->
66
<mat-accordion class="example-headers-align" multi>
7-
<!-- #enddocregion multi -->
7+
<!-- #enddocregion multi -->
88
<mat-expansion-panel>
99
<mat-expansion-panel-header>
10-
<mat-panel-title>
11-
Personal data
12-
</mat-panel-title>
10+
<mat-panel-title> Personal data </mat-panel-title>
1311
<mat-panel-description>
1412
Type your name and age
1513
<mat-icon>account_circle</mat-icon>
@@ -18,22 +16,19 @@
1816

1917
<mat-form-field>
2018
<mat-label>First name</mat-label>
21-
<input matInput>
19+
<input matInput />
2220
</mat-form-field>
2321

2422
<mat-form-field>
2523
<mat-label>Age</mat-label>
26-
<input matInput type="number" min="1">
24+
<input matInput type="number" min="1" />
2725
</mat-form-field>
28-
2926
</mat-expansion-panel>
30-
<!-- #docregion disabled -->
27+
<!-- #docregion disabled -->
3128
<mat-expansion-panel disabled>
32-
<!-- #enddocregion disabled -->
29+
<!-- #enddocregion disabled -->
3330
<mat-expansion-panel-header>
34-
<mat-panel-title>
35-
Destination
36-
</mat-panel-title>
31+
<mat-panel-title> Destination </mat-panel-title>
3732
<mat-panel-description>
3833
Type the country name
3934
<mat-icon>map</mat-icon>
@@ -42,15 +37,13 @@
4237

4338
<mat-form-field>
4439
<mat-label>Country</mat-label>
45-
<input matInput>
40+
<input matInput />
4641
</mat-form-field>
4742
</mat-expansion-panel>
4843

4944
<mat-expansion-panel>
5045
<mat-expansion-panel-header>
51-
<mat-panel-title>
52-
Day of the trip
53-
</mat-panel-title>
46+
<mat-panel-title> Day of the trip </mat-panel-title>
5447
<mat-panel-description>
5548
Inform the date you wish to travel
5649
<mat-icon>date_range</mat-icon>
@@ -59,7 +52,7 @@
5952

6053
<mat-form-field>
6154
<mat-label>Date</mat-label>
62-
<input matInput [matDatepicker]="picker" (focus)="picker.open()" readonly>
55+
<input matInput [matDatepicker]="picker" (focus)="picker.open()" readonly />
6356
</mat-form-field>
6457
<mat-datepicker #picker></mat-datepicker>
6558
</mat-expansion-panel>

src/components-examples/material/expansion/expansion-expand-collapse-all/expansion-expand-collapse-all-example.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {Component, ViewChild} from '@angular/core';
2-
import {MatAccordion, MatExpansionModule} from '@angular/material/expansion';
1+
import {ChangeDetectionStrategy, Component, viewChild} from '@angular/core';
2+
import {MatButtonModule} from '@angular/material/button';
3+
import {provideNativeDateAdapter} from '@angular/material/core';
34
import {MatDatepickerModule} from '@angular/material/datepicker';
4-
import {MatInputModule} from '@angular/material/input';
5+
import {MatAccordion, MatExpansionModule} from '@angular/material/expansion';
56
import {MatFormFieldModule} from '@angular/material/form-field';
67
import {MatIconModule} from '@angular/material/icon';
7-
import {MatButtonModule} from '@angular/material/button';
8-
import {provideNativeDateAdapter} from '@angular/material/core';
8+
import {MatInputModule} from '@angular/material/input';
99

1010
/**
1111
* @title Accordion with expand/collapse all toggles
@@ -24,7 +24,8 @@ import {provideNativeDateAdapter} from '@angular/material/core';
2424
MatInputModule,
2525
MatDatepickerModule,
2626
],
27+
changeDetection: ChangeDetectionStrategy.OnPush,
2728
})
2829
export class ExpansionExpandCollapseAllExample {
29-
@ViewChild(MatAccordion) accordion: MatAccordion;
30+
accordion = viewChild.required(MatAccordion);
3031
}

src/components-examples/material/expansion/expansion-harness/expansion-harness-example.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component} from '@angular/core';
1+
import {ChangeDetectionStrategy, Component} from '@angular/core';
22
import {MatExpansionModule} from '@angular/material/expansion';
33

44
/**
@@ -9,5 +9,6 @@ import {MatExpansionModule} from '@angular/material/expansion';
99
templateUrl: 'expansion-harness-example.html',
1010
standalone: true,
1111
imports: [MatExpansionModule],
12+
changeDetection: ChangeDetectionStrategy.OnPush,
1213
})
1314
export class ExpansionHarnessExample {}

src/components-examples/material/expansion/expansion-overview/expansion-overview-example.html

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
<mat-accordion>
2-
<!-- #docregion basic-panel -->
3-
<!-- #docregion hide-toggle -->
2+
<!-- #docregion basic-panel -->
3+
<!-- #docregion hide-toggle -->
44
<mat-expansion-panel hideToggle>
5-
<!-- #enddocregion hide-toggle -->
5+
<!-- #enddocregion hide-toggle -->
66
<mat-expansion-panel-header>
7-
<mat-panel-title>
8-
This is the expansion title
9-
</mat-panel-title>
10-
<mat-panel-description>
11-
This is a summary of the content
12-
</mat-panel-description>
7+
<mat-panel-title> This is the expansion title </mat-panel-title>
8+
<mat-panel-description> This is a summary of the content </mat-panel-description>
139
</mat-expansion-panel-header>
1410
<p>This is the primary content of the panel.</p>
1511
</mat-expansion-panel>
16-
<!-- #enddocregion basic-panel -->
17-
<mat-expansion-panel (opened)="panelOpenState = true"
18-
(closed)="panelOpenState = false">
12+
<!-- #enddocregion basic-panel -->
13+
<mat-expansion-panel (opened)="panelOpenState.set(true)" (closed)="panelOpenState.set(false)">
1914
<mat-expansion-panel-header>
20-
<mat-panel-title>
21-
Self aware panel
22-
</mat-panel-title>
15+
<mat-panel-title> Self aware panel </mat-panel-title>
2316
<mat-panel-description>
24-
Currently I am {{panelOpenState ? 'open' : 'closed'}}
17+
Currently I am {{panelOpenState() ? 'open' : 'closed'}}
2518
</mat-panel-description>
2619
</mat-expansion-panel-header>
2720
<p>I'm visible because I am open</p>

src/components-examples/material/expansion/expansion-overview/expansion-overview-example.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component} from '@angular/core';
1+
import {ChangeDetectionStrategy, Component, signal} from '@angular/core';
22
import {MatExpansionModule} from '@angular/material/expansion';
33

44
/**
@@ -9,7 +9,8 @@ import {MatExpansionModule} from '@angular/material/expansion';
99
templateUrl: 'expansion-overview-example.html',
1010
standalone: true,
1111
imports: [MatExpansionModule],
12+
changeDetection: ChangeDetectionStrategy.OnPush,
1213
})
1314
export class ExpansionOverviewExample {
14-
panelOpenState = false;
15+
readonly panelOpenState = signal(false);
1516
}
Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<mat-accordion class="example-headers-align">
2-
<mat-expansion-panel [expanded]="step === 0" (opened)="setStep(0)" hideToggle>
2+
<mat-expansion-panel [expanded]="step() === 0" (opened)="setStep(0)" hideToggle>
33
<mat-expansion-panel-header>
4-
<mat-panel-title>
5-
Personal data
6-
</mat-panel-title>
4+
<mat-panel-title> Personal data </mat-panel-title>
75
<mat-panel-description>
86
Type your name and age
97
<mat-icon>account_circle</mat-icon>
@@ -12,25 +10,23 @@
1210

1311
<mat-form-field>
1412
<mat-label>First name</mat-label>
15-
<input matInput>
13+
<input matInput />
1614
</mat-form-field>
1715

1816
<mat-form-field>
1917
<mat-label>Age</mat-label>
20-
<input matInput type="number" min="1">
18+
<input matInput type="number" min="1" />
2119
</mat-form-field>
22-
<!-- #docregion action-bar -->
20+
<!-- #docregion action-bar -->
2321
<mat-action-row>
2422
<button mat-button color="primary" (click)="nextStep()">Next</button>
2523
</mat-action-row>
26-
<!-- #enddocregion action-bar -->
24+
<!-- #enddocregion action-bar -->
2725
</mat-expansion-panel>
2826

29-
<mat-expansion-panel [expanded]="step === 1" (opened)="setStep(1)" hideToggle>
27+
<mat-expansion-panel [expanded]="step() === 1" (opened)="setStep(1)" hideToggle>
3028
<mat-expansion-panel-header>
31-
<mat-panel-title>
32-
Destination
33-
</mat-panel-title>
29+
<mat-panel-title> Destination </mat-panel-title>
3430
<mat-panel-description>
3531
Type the country name
3632
<mat-icon>map</mat-icon>
@@ -39,7 +35,7 @@
3935

4036
<mat-form-field>
4137
<mat-label>Country</mat-label>
42-
<input matInput>
38+
<input matInput />
4339
</mat-form-field>
4440

4541
<mat-action-row>
@@ -48,11 +44,9 @@
4844
</mat-action-row>
4945
</mat-expansion-panel>
5046

51-
<mat-expansion-panel [expanded]="step === 2" (opened)="setStep(2)" hideToggle>
47+
<mat-expansion-panel [expanded]="step() === 2" (opened)="setStep(2)" hideToggle>
5248
<mat-expansion-panel-header>
53-
<mat-panel-title>
54-
Day of the trip
55-
</mat-panel-title>
49+
<mat-panel-title> Day of the trip </mat-panel-title>
5650
<mat-panel-description>
5751
Inform the date you wish to travel
5852
<mat-icon>date_range</mat-icon>
@@ -61,7 +55,7 @@
6155

6256
<mat-form-field>
6357
<mat-label>Date</mat-label>
64-
<input matInput [matDatepicker]="picker" (focus)="picker.open()" readonly>
58+
<input matInput [matDatepicker]="picker" (focus)="picker.open()" readonly />
6559
</mat-form-field>
6660
<mat-datepicker #picker></mat-datepicker>
6761

@@ -70,5 +64,4 @@
7064
<button mat-button color="primary" (click)="nextStep()">End</button>
7165
</mat-action-row>
7266
</mat-expansion-panel>
73-
7467
</mat-accordion>

src/components-examples/material/expansion/expansion-steps/expansion-steps-example.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {Component} from '@angular/core';
2-
import {MatDatepickerModule} from '@angular/material/datepicker';
1+
import {ChangeDetectionStrategy, Component, signal} from '@angular/core';
32
import {MatButtonModule} from '@angular/material/button';
4-
import {MatInputModule} from '@angular/material/input';
3+
import {provideNativeDateAdapter} from '@angular/material/core';
4+
import {MatDatepickerModule} from '@angular/material/datepicker';
5+
import {MatExpansionModule} from '@angular/material/expansion';
56
import {MatFormFieldModule} from '@angular/material/form-field';
67
import {MatIconModule} from '@angular/material/icon';
7-
import {MatExpansionModule} from '@angular/material/expansion';
8-
import {provideNativeDateAdapter} from '@angular/material/core';
8+
import {MatInputModule} from '@angular/material/input';
99

1010
/**
1111
* @title Expansion panel as accordion
@@ -24,19 +24,20 @@ import {provideNativeDateAdapter} from '@angular/material/core';
2424
MatButtonModule,
2525
MatDatepickerModule,
2626
],
27+
changeDetection: ChangeDetectionStrategy.OnPush,
2728
})
2829
export class ExpansionStepsExample {
29-
step = 0;
30+
step = signal(0);
3031

3132
setStep(index: number) {
32-
this.step = index;
33+
this.step.set(index);
3334
}
3435

3536
nextStep() {
36-
this.step++;
37+
this.step.update(i => i + 1);
3738
}
3839

3940
prevStep() {
40-
this.step--;
41+
this.step.update(i => i - 1);
4142
}
4243
}

src/material/expansion/expansion.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,33 @@ as the control for expanding and collapsing. This header may optionally contain
1212
header to align with Material Design specifications.
1313

1414
<!-- example({"example": "expansion-overview",
15-
"file": "expansion-overview-example.html",
15+
"file": "expansion-overview-example.html",
1616
"region": "basic-panel"}) -->
17-
17+
1818
By default, the expansion-panel header includes a toggle icon at the end of the
1919
header to indicate the expansion state. This icon can be hidden via the
2020
`hideToggle` property.
2121

2222
<!-- example({"example": "expansion-overview",
2323
"file": "expansion-overview-example.html",
24-
"region": "hide-toggle"}) -->
24+
"region": "hide-toggle"}) -->
2525

2626
#### Action bar
2727

2828
Actions may optionally be included at the bottom of the panel, visible only when the expansion
2929
is in its expanded state.
3030

3131
<!-- example({"example": "expansion-steps",
32-
"file": "expansion-steps-example.html",
32+
"file": "expansion-steps-example.html",
3333
"region": "action-bar"}) -->
34+
3435
#### Disabling a panel
3536

3637
Expansion panels can be disabled using the `disabled` attribute. A disabled expansion panel can't
3738
be toggled by the user, but can still be manipulated programmatically.
3839

3940
<!-- example({"example": "expansion-expand-collapse-all",
40-
"file": "expansion-expand-collapse-all-example.html",
41+
"file": "expansion-expand-collapse-all-example.html",
4142
"region": "disabled"}) -->
4243

4344
### Accordion
@@ -47,13 +48,15 @@ expansions state to be set independently of each other. When `multi="false"` (de
4748
panel can be expanded at a given time:
4849

4950
<!-- example({"example": "expansion-expand-collapse-all",
50-
"file": "expansion-expand-collapse-all-example.html",
51+
"file": "expansion-expand-collapse-all-example.html",
5152
"region": "multi"}) -->
5253

5354
### Lazy rendering
55+
5456
By default, the expansion panel content will be initialized even when the panel is closed.
5557
To instead defer initialization until the panel is open, the content should be provided as
5658
an `ng-template`:
59+
5760
```html
5861
<mat-expansion-panel>
5962
<mat-expansion-panel-header>

0 commit comments

Comments
 (0)