Skip to content

Commit 1cfce4c

Browse files
author
Sam Severance
committed
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 0d43581 commit 1cfce4c

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
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
@@ -45,12 +45,33 @@
4545
flex: 1;
4646
flex-direction: row;
4747
overflow: hidden;
48+
49+
// width of .mat-expansion-indicator::after element
50+
&.mat-content-hide-toggle {
51+
margin-right: 8px;
52+
53+
[dir='rtl'] & {
54+
margin-right: 0;
55+
margin-left: 8px;
56+
}
57+
58+
.mat-expansion-toggle-indicator-before & {
59+
margin-left: 24px;
60+
margin-right: 0;
61+
62+
[dir='rtl'] & {
63+
margin-right: 24px;
64+
margin-left: 0;
65+
}
66+
}
67+
}
4868
}
4969

5070
.mat-expansion-panel-header-title,
5171
.mat-expansion-panel-header-description {
5272
display: flex;
5373
flex-grow: 1;
74+
flex-basis: 0;
5475
margin-right: 16px;
5576

5677
[dir='rtl'] & {

src/material/expansion/expansion.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,20 @@ describe('MatExpansionPanel', () => {
245245
it('should be able to hide the toggle', () => {
246246
const fixture = TestBed.createComponent(PanelWithContent);
247247
const header = fixture.debugElement.query(By.css('.mat-expansion-panel-header'))!.nativeElement;
248+
const content = fixture.debugElement.query(By.css('.mat-content'))!.nativeElement;
248249

249250
fixture.detectChanges();
250251

251252
expect(header.querySelector('.mat-expansion-indicator'))
252253
.toBeTruthy('Expected indicator to be shown.');
254+
expect(content.classList).not.toContain('mat-content-hide-toggle');
253255

254256
fixture.componentInstance.hideToggle = true;
255257
fixture.detectChanges();
256258

257259
expect(header.querySelector('.mat-expansion-indicator'))
258260
.toBeFalsy('Expected indicator to be hidden.');
261+
expect(content.classList).toContain('mat-content-hide-toggle');
259262
});
260263

261264
it('should update the indicator rotation when the expanded state is toggled programmatically',

0 commit comments

Comments
 (0)