Skip to content

Commit a718c20

Browse files
Sam Severanceswseverance
authored andcommitted
fix(expansion): fix expansion .mat-expansion-panel-header styles
* 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
1 parent 82359e0 commit a718c20

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
@@ -48,12 +48,33 @@
4848
flex: 1;
4949
flex-direction: row;
5050
overflow: hidden;
51+
52+
// width of .mat-expansion-indicator::after element
53+
&.mat-content-hide-toggle {
54+
margin-right: 8px;
55+
56+
[dir='rtl'] & {
57+
margin-right: 0;
58+
margin-left: 8px;
59+
}
60+
61+
.mat-expansion-toggle-indicator-before & {
62+
margin-left: 24px;
63+
margin-right: 0;
64+
65+
[dir='rtl'] & {
66+
margin-right: 24px;
67+
margin-left: 0;
68+
}
69+
}
70+
}
5171
}
5272

5373
.mat-expansion-panel-header-title,
5474
.mat-expansion-panel-header-description {
5575
display: flex;
5676
flex-grow: 1;
77+
flex-basis: 0;
5778
margin-right: 16px;
5879
align-items: center;
5980

src/material/expansion/expansion.spec.ts

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

6464
it('should be able to render panel content lazily', fakeAsync(() => {
6565
const fixture = TestBed.createComponent(LazyPanelWithContent);
66-
const content = fixture.debugElement.query(
67-
By.css('.mat-expansion-panel-content'),
68-
)!.nativeElement;
66+
const content = fixture.debugElement.query(By.css('.mat-expansion-panel-content'))!
67+
.nativeElement;
6968
fixture.detectChanges();
7069

7170
expect(content.textContent.trim())
@@ -82,9 +81,8 @@ describe('MatExpansionPanel', () => {
8281

8382
it('should render the content for a lazy-loaded panel that is opened on init', fakeAsync(() => {
8483
const fixture = TestBed.createComponent(LazyPanelOpenOnLoad);
85-
const content = fixture.debugElement.query(
86-
By.css('.mat-expansion-panel-content'),
87-
)!.nativeElement;
84+
const content = fixture.debugElement.query(By.css('.mat-expansion-panel-content'))!
85+
.nativeElement;
8886
fixture.detectChanges();
8987

9088
expect(content.textContent.trim())
@@ -314,19 +312,22 @@ describe('MatExpansionPanel', () => {
314312
it('should be able to hide the toggle', () => {
315313
const fixture = TestBed.createComponent(PanelWithContent);
316314
const header = fixture.debugElement.query(By.css('.mat-expansion-panel-header'))!.nativeElement;
315+
const content = fixture.debugElement.query(By.css('.mat-content'))!.nativeElement;
317316

318317
fixture.detectChanges();
319318

320319
expect(header.querySelector('.mat-expansion-indicator'))
321320
.withContext('Expected indicator to be shown.')
322321
.toBeTruthy();
322+
expect(content.classList).not.toContain('mat-content-hide-toggle');
323323

324324
fixture.componentInstance.hideToggle = true;
325325
fixture.detectChanges();
326326

327327
expect(header.querySelector('.mat-expansion-indicator'))
328328
.withContext('Expected indicator to be hidden.')
329329
.toBeFalsy();
330+
expect(content.classList).toContain('mat-content-hide-toggle');
330331
});
331332

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

0 commit comments

Comments
 (0)