Skip to content

Commit b1450b1

Browse files
swseveranceandrewseguin
authored andcommitted
fix(expansion): fix expansion .mat-expansion-panel-header styles (#20019)
* Add margin to `.mat-content` element to account for consumer using `mat-expansion-panel` components with the toggle hidden alongside `mat-expansion-panel` components where the toggle is visible * Adjust sizing of `.mat-expansion-panel-header-title` and `.mat-expansion-panel-header-description` elements so that the width of each respective element is uniform across multiple adjacent `mat-expansion-panel` elements * Fixes #20002 (cherry picked from commit 2615b5f)
1 parent f661a93 commit b1450b1

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
padding-bottom: 20px;
33
}
44

5-
.example-headers-align .mat-expansion-panel-header-title,
6-
.example-headers-align .mat-expansion-panel-header-description {
7-
flex-basis: 0;
8-
}
9-
105
.example-headers-align .mat-expansion-panel-header-description {
116
justify-content: space-between;
127
align-items: center;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
.example-headers-align .mat-expansion-panel-header-title,
2-
.example-headers-align .mat-expansion-panel-header-description {
3-
flex-basis: 0;
4-
}
5-
61
.example-headers-align .mat-expansion-panel-header-description {
72
justify-content: space-between;
83
align-items: center;

src/material/expansion/expansion-panel-header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<span class="mat-content">
1+
<span class="mat-content" [class.mat-content-hide-toggle]="!_showToggle()">
22
<ng-content select="mat-panel-title"></ng-content>
33
<ng-content select="mat-panel-description"></ng-content>
44
<ng-content></ng-content>

src/material/expansion/expansion-panel-header.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,33 @@
4646
flex: 1;
4747
flex-direction: row;
4848
overflow: hidden;
49+
50+
// width of .mat-expansion-indicator::after element
51+
&.mat-content-hide-toggle {
52+
margin-right: 8px;
53+
54+
[dir='rtl'] & {
55+
margin-right: 0;
56+
margin-left: 8px;
57+
}
58+
59+
.mat-expansion-toggle-indicator-before & {
60+
margin-left: 24px;
61+
margin-right: 0;
62+
63+
[dir='rtl'] & {
64+
margin-right: 24px;
65+
margin-left: 0;
66+
}
67+
}
68+
}
4969
}
5070

5171
.mat-expansion-panel-header-title,
5272
.mat-expansion-panel-header-description {
5373
display: flex;
5474
flex-grow: 1;
75+
flex-basis: 0;
5576
margin-right: 16px;
5677
align-items: center;
5778

src/material/expansion/expansion.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ describe('MatExpansionPanel', () => {
6161

6262
it('should be able to render panel content lazily', fakeAsync(() => {
6363
const fixture = TestBed.createComponent(LazyPanelWithContent);
64-
const content = fixture.debugElement.query(
65-
By.css('.mat-expansion-panel-content'),
66-
)!.nativeElement;
64+
const content = fixture.debugElement.query(By.css('.mat-expansion-panel-content'))!
65+
.nativeElement;
6766
fixture.detectChanges();
6867

6968
expect(content.textContent.trim())
@@ -80,9 +79,8 @@ describe('MatExpansionPanel', () => {
8079

8180
it('should render the content for a lazy-loaded panel that is opened on init', fakeAsync(() => {
8281
const fixture = TestBed.createComponent(LazyPanelOpenOnLoad);
83-
const content = fixture.debugElement.query(
84-
By.css('.mat-expansion-panel-content'),
85-
)!.nativeElement;
82+
const content = fixture.debugElement.query(By.css('.mat-expansion-panel-content'))!
83+
.nativeElement;
8684
fixture.detectChanges();
8785

8886
expect(content.textContent.trim())
@@ -312,19 +310,22 @@ describe('MatExpansionPanel', () => {
312310
it('should be able to hide the toggle', () => {
313311
const fixture = TestBed.createComponent(PanelWithContent);
314312
const header = fixture.debugElement.query(By.css('.mat-expansion-panel-header'))!.nativeElement;
313+
const content = fixture.debugElement.query(By.css('.mat-content'))!.nativeElement;
315314

316315
fixture.detectChanges();
317316

318317
expect(header.querySelector('.mat-expansion-indicator'))
319318
.withContext('Expected indicator to be shown.')
320319
.toBeTruthy();
320+
expect(content.classList).not.toContain('mat-content-hide-toggle');
321321

322322
fixture.componentInstance.hideToggle = true;
323323
fixture.detectChanges();
324324

325325
expect(header.querySelector('.mat-expansion-indicator'))
326326
.withContext('Expected indicator to be hidden.')
327327
.toBeFalsy();
328+
expect(content.classList).toContain('mat-content-hide-toggle');
328329
});
329330

330331
it('should update the indicator rotation when the expanded state is toggled programmatically', fakeAsync(() => {

0 commit comments

Comments
 (0)