Skip to content

Commit

Permalink
fix(expansion): fix expansion .mat-expansion-panel-header styles
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Sam Severance committed Jul 17, 2020
1 parent 0d43581 commit 1cfce4c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
padding-bottom: 20px;
}

.example-headers-align .mat-expansion-panel-header-title,
.example-headers-align .mat-expansion-panel-header-description {
flex-basis: 0;
}

.example-headers-align .mat-expansion-panel-header-description {
justify-content: space-between;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
.example-headers-align .mat-expansion-panel-header-title,
.example-headers-align .mat-expansion-panel-header-description {
flex-basis: 0;
}

.example-headers-align .mat-expansion-panel-header-description {
justify-content: space-between;
align-items: center;
Expand Down
2 changes: 1 addition & 1 deletion src/material/expansion/expansion-panel-header.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<span class="mat-content">
<span class="mat-content" [class.mat-content-hide-toggle]="!_showToggle()">
<ng-content select="mat-panel-title"></ng-content>
<ng-content select="mat-panel-description"></ng-content>
<ng-content></ng-content>
Expand Down
21 changes: 21 additions & 0 deletions src/material/expansion/expansion-panel-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,33 @@
flex: 1;
flex-direction: row;
overflow: hidden;

// width of .mat-expansion-indicator::after element
&.mat-content-hide-toggle {
margin-right: 8px;

[dir='rtl'] & {
margin-right: 0;
margin-left: 8px;
}

.mat-expansion-toggle-indicator-before & {
margin-left: 24px;
margin-right: 0;

[dir='rtl'] & {
margin-right: 24px;
margin-left: 0;
}
}
}
}

.mat-expansion-panel-header-title,
.mat-expansion-panel-header-description {
display: flex;
flex-grow: 1;
flex-basis: 0;
margin-right: 16px;

[dir='rtl'] & {
Expand Down
3 changes: 3 additions & 0 deletions src/material/expansion/expansion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,20 @@ describe('MatExpansionPanel', () => {
it('should be able to hide the toggle', () => {
const fixture = TestBed.createComponent(PanelWithContent);
const header = fixture.debugElement.query(By.css('.mat-expansion-panel-header'))!.nativeElement;
const content = fixture.debugElement.query(By.css('.mat-content'))!.nativeElement;

fixture.detectChanges();

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

fixture.componentInstance.hideToggle = true;
fixture.detectChanges();

expect(header.querySelector('.mat-expansion-indicator'))
.toBeFalsy('Expected indicator to be hidden.');
expect(content.classList).toContain('mat-content-hide-toggle');
});

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

0 comments on commit 1cfce4c

Please sign in to comment.