Skip to content

Commit f1f34bc

Browse files
authored
Revert "feat(expansion): allow expansion indicator positioning." (#11466)
This reverts commit 51d859f.
1 parent 51d859f commit f1f34bc

12 files changed

+37
-155
lines changed

src/demo-app/expansion/expansion-demo.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ <h1>matAccordion</h1>
4343
<mat-radio-button value="default">Default</mat-radio-button>
4444
<mat-radio-button value="flat">Flat</mat-radio-button>
4545
</mat-radio-group>
46-
<p>Toggle Position</p>
47-
<mat-radio-group [(ngModel)]="togglePosition">
48-
<mat-radio-button value="before">Before</mat-radio-button>
49-
<mat-radio-button value="after">After</mat-radio-button>
50-
</mat-radio-group>
5146
<p>Accordion Actions <sup>('Multi Expansion' mode only)</sup></p>
5247
<div>
5348
<button mat-button (click)="accordion.openAll()" [disabled]="!multi">Expand All</button>
@@ -60,8 +55,8 @@ <h1>matAccordion</h1>
6055
</div>
6156
</div>
6257
<br>
63-
<mat-accordion [displayMode]="displayMode" [multi]="multi" [togglePosition]="togglePosition"
64-
class="demo-expansion-width">
58+
<mat-accordion [displayMode]="displayMode" [multi]="multi"
59+
class="demo-expansion-width">
6560
<mat-expansion-panel #panel1 [hideToggle]="hideToggle">
6661
<mat-expansion-panel-header>Section 1</mat-expansion-panel-header>
6762
<p>This is the content text that makes sense here.</p>
@@ -80,7 +75,7 @@ <h1>matAccordion</h1>
8075
</mat-expansion-panel>
8176
</mat-accordion>
8277

83-
<h1>CdkAccordion</h1>
78+
<h1>cdkAccordion</h1>
8479
<div>
8580
<p>Accordion Options</p>
8681
<div>
@@ -113,3 +108,4 @@ <h1>CdkAccordion</h1>
113108
<p *ngIf="item3.expanded">I only show if item 3 is expanded</p>
114109
</cdk-accordion-item>
115110
</cdk-accordion>
111+

src/demo-app/expansion/expansion-demo.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export class ExpansionDemo {
2020
@ViewChild(MatAccordion) accordion: MatAccordion;
2121

2222
displayMode = 'default';
23-
togglePosition = 'after';
2423
multi = false;
2524
hideToggle = false;
2625
disabled = false;

src/lib/expansion/_expansion-theme.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131

3232
.mat-expansion-panel-header-description,
33-
.mat-expansion-indicator {
33+
.mat-expansion-indicator::after {
3434
color: mat-color($foreground, secondary-text);
3535
}
3636

src/lib/expansion/accordion.spec.ts

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
55
import {MatExpansionModule, MatAccordion} from './index';
66

77

8-
describe('MatAccordion', () => {
8+
describe('CdkAccordion', () => {
99
beforeEach(async(() => {
1010
TestBed.configureTestingModule({
1111
imports: [
@@ -83,39 +83,12 @@ describe('MatAccordion', () => {
8383
fixture.detectChanges();
8484
expect(panels[0].classes['mat-expanded']).toBeFalsy();
8585
expect(panels[1].classes['mat-expanded']).toBeFalsy();
86-
87-
});
88-
89-
it('should correctly apply the displayMode provided', () => {
90-
const fixture = TestBed.createComponent(SetOfItems);
91-
const firstPanel = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'))[0];
92-
93-
fixture.componentInstance.firstPanelExpanded = true;
94-
fixture.detectChanges();
95-
expect(firstPanel.classes['mat-expansion-panel-spacing']).toBeTruthy();
96-
97-
fixture.componentInstance.displayMode = 'flat';
98-
fixture.detectChanges();
99-
expect(firstPanel.classes['mat-expansion-panel-spacing']).toBeFalsy();
100-
});
101-
102-
it('should correctly apply the togglePosition provided', () => {
103-
const fixture = TestBed.createComponent(SetOfItems);
104-
fixture.detectChanges();
105-
const firstPanelHeader =
106-
fixture.debugElement.queryAll(By.css('.mat-expansion-indicator-container'))[0];
107-
108-
expect(firstPanelHeader.classes['mat-expansion-indicator-container-before']).toBeFalsy();
109-
110-
fixture.componentInstance.togglePosition = 'before';
111-
fixture.detectChanges();
112-
expect(firstPanelHeader.classes['mat-expansion-indicator-container-before']).toBeTruthy();
11386
});
11487
});
11588

11689

11790
@Component({template: `
118-
<mat-accordion [multi]="multi" [displayMode]="displayMode" [togglePosition]="togglePosition">
91+
<mat-accordion [multi]="multi">
11992
<mat-expansion-panel [expanded]="firstPanelExpanded">
12093
<mat-expansion-panel-header>Summary</mat-expansion-panel-header>
12194
<p>Content</p>
@@ -129,8 +102,6 @@ class SetOfItems {
129102
@ViewChild(MatAccordion) accordion: MatAccordion;
130103

131104
multi: boolean = false;
132-
displayMode = 'default';
133-
togglePosition = 'after';
134105
firstPanelExpanded: boolean = false;
135106
secondPanelExpanded: boolean = false;
136107
secondPanelDisabled: boolean = false;

src/lib/expansion/accordion.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Directive, Input, SimpleChanges} from '@angular/core';
9+
import {Directive, Input} from '@angular/core';
1010
import {coerceBooleanProperty} from '@angular/cdk/coercion';
1111
import {CdkAccordion} from '@angular/cdk/accordion';
12-
import {Subject} from 'rxjs';
1312

1413
/** MatAccordion's display modes. */
1514
export type MatAccordionDisplayMode = 'default' | 'flat';
1615

17-
18-
/** MatAccordion's toggle positions. */
19-
export type MatAccordionTogglePosition = 'before' | 'after';
20-
2116
/**
2217
* Directive for a Material Design Accordion.
2318
*/
@@ -29,9 +24,6 @@ export type MatAccordionDisplayMode = 'default' | 'flat';
2924
}
3025
})
3126
export class MatAccordion extends CdkAccordion {
32-
/** Stream that emits for changes in `@Input` properties. */
33-
_inputChanges = new Subject<SimpleChanges>();
34-
3527
/** Whether the expansion indicator should be hidden. */
3628
@Input()
3729
get hideToggle(): boolean { return this._hideToggle; }
@@ -47,15 +39,4 @@ export class MatAccordion extends CdkAccordion {
4739
* elevation.
4840
*/
4941
@Input() displayMode: MatAccordionDisplayMode = 'default';
50-
51-
/** The positioning of the expansion indicator. */
52-
@Input() togglePosition: MatAccordionTogglePosition = 'after';
53-
54-
ngOnChanges(changes: SimpleChanges) {
55-
this._inputChanges.next(changes);
56-
}
57-
58-
ngOnDestroy() {
59-
this._inputChanges.complete();
60-
}
6142
}

src/lib/expansion/expansion-animations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const matExpansionAnimations: {
2828
} = {
2929
/** Animation that rotates the indicator arrow. */
3030
indicatorRotate: trigger('indicatorRotate', [
31-
state('collapsed', style({transform: 'rotate(45deg)'})),
32-
state('expanded', style({transform: 'rotate(225deg)'})),
31+
state('collapsed', style({transform: 'rotate(0deg)'})),
32+
state('expanded', style({transform: 'rotate(180deg)'})),
3333
transition('expanded <=> collapsed', animate(EXPANSION_PANEL_ANIMATION_TIMING)),
3434
]),
3535

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
<ng-content select="mat-panel-description"></ng-content>
44
<ng-content></ng-content>
55
</span>
6-
<div class="mat-expansion-indicator-container"
7-
[class.mat-expansion-indicator-container-before]="_placeToggleBefore()">
8-
<span *ngIf="_isToggleVisible()" class="mat-expansion-indicator"
9-
[@indicatorRotate]="_getExpandedState()"></span>
10-
</div>
6+
<span [@indicatorRotate]="_getExpandedState()" *ngIf="_showToggle()"
7+
class="mat-expansion-indicator"></span>
Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
12
.mat-expansion-panel-header {
23
display: flex;
34
flex-direction: row;
45
align-items: center;
5-
padding: 0 16px;
6+
padding: 0 24px;
67

78
&:focus,
89
&:hover {
@@ -24,13 +25,12 @@
2425
flex: 1;
2526
flex-direction: row;
2627
overflow: hidden;
27-
padding-left: 8px;
2828
}
2929

3030
.mat-expansion-panel-header-title,
3131
.mat-expansion-panel-header-description {
3232
display: flex;
33-
flex: 1;
33+
flex-grow: 1;
3434
margin-right: 16px;
3535

3636
[dir='rtl'] & {
@@ -40,37 +40,19 @@
4040
}
4141

4242
.mat-expansion-panel-header-description {
43-
flex: 2;
44-
}
45-
46-
.mat-expansion-indicator-container {
47-
// A margin is required to offset the entire expansion indicator against the space the arrow
48-
// takes up. It is calculated as sqrt(2 * border-width ^ 2) / 2.
49-
margin-bottom: 1.41px;
50-
padding: 0 8px 0 0;
51-
width: 8px;
52-
order: 1;
53-
54-
&.mat-expansion-indicator-container-before {
55-
order: -1;
56-
padding: 0 8px;
57-
}
43+
flex-grow: 2;
5844
}
5945

60-
.mat-expansion-indicator {
46+
/**
47+
* Creates the expansion indicator arrow. Done using ::after rather than having
48+
* additional nodes in the template.
49+
*/
50+
.mat-expansion-indicator::after {
6151
border-style: solid;
6252
border-width: 0 2px 2px 0;
63-
display: block;
64-
height: 6px;
53+
content: '';
54+
display: inline-block;
55+
padding: 3px;
6556
transform: rotate(45deg);
66-
// The transform origin is set by determining the center pointer of the arrow created. It is
67-
// calculated as by calculating the length of the line between the top left corner of the div,
68-
// and the centroid of the triangle created in the bottom right half of the div. This centroid
69-
// is calculated for both X and Y (as the indicator is a square) as
70-
// (indicator-width + indicator-height + 0) / 3
71-
// The length between the resulting coordinates and the top left (0, 0) of the div are
72-
// calculated sqrt((centroids-x-coord ^ 2) + (centroids-y-coord ^ 2))
73-
// This value is used to transform the origin on both the X and Y axes.
74-
transform-origin: 5.65px 5.65px;
75-
width: 6px;
57+
vertical-align: middle;
7658
}

src/lib/expansion/expansion-panel-header.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ import {
1616
ElementRef,
1717
Host,
1818
Input,
19-
Optional,
2019
OnDestroy,
2120
ViewEncapsulation,
2221
} from '@angular/core';
2322
import {merge, Subscription} from 'rxjs';
2423
import {filter} from 'rxjs/operators';
2524
import {matExpansionAnimations} from './expansion-animations';
2625
import {MatExpansionPanel} from './expansion-panel';
27-
import {MatAccordion} from './accordion';
2826

2927

3028
/**
@@ -67,24 +65,17 @@ export class MatExpansionPanelHeader implements OnDestroy {
6765
private _parentChangeSubscription = Subscription.EMPTY;
6866

6967
constructor(
70-
@Optional() accordion: MatAccordion,
7168
@Host() public panel: MatExpansionPanel,
7269
private _element: ElementRef,
7370
private _focusMonitor: FocusMonitor,
7471
private _changeDetectorRef: ChangeDetectorRef) {
7572

76-
let changeStreams = [panel._inputChanges];
77-
if (accordion) {
78-
changeStreams.push(accordion._inputChanges);
79-
}
80-
8173
// Since the toggle state depends on an @Input on the panel, we
82-
// need to subscribe and trigger change detection manually.
74+
// need to subscribe and trigger change detection manually.
8375
this._parentChangeSubscription = merge(
8476
panel.opened,
8577
panel.closed,
86-
merge(...changeStreams).pipe(
87-
filter(changes => !!(changes.hideToggle || changes.disabled || changes.togglePosition)))
78+
panel._inputChanges.pipe(filter(changes => !!(changes.hideToggle || changes.disabled)))
8879
)
8980
.subscribe(() => this._changeDetectorRef.markForCheck());
9081

@@ -118,15 +109,10 @@ export class MatExpansionPanelHeader implements OnDestroy {
118109
}
119110

120111
/** Gets whether the expand indicator should be shown. */
121-
_isToggleVisible(): boolean {
112+
_showToggle(): boolean {
122113
return !this.panel.hideToggle && !this.panel.disabled;
123114
}
124115

125-
/** Whether the expand indicator should be shown before the header content */
126-
_placeToggleBefore(): boolean {
127-
return this.panel.togglePosition === 'before';
128-
}
129-
130116
/** Handle keydown event calling to toggle() if appropriate. */
131117
_keydown(event: KeyboardEvent) {
132118
switch (event.keyCode) {

src/lib/expansion/expansion-panel.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import {
2828
} from '@angular/core';
2929
import {Subject} from 'rxjs';
3030
import {filter, startWith, take} from 'rxjs/operators';
31-
import {MatAccordion, MatAccordionTogglePosition} from './accordion';
32-
import {MatExpansionPanelContent} from './expansion-panel-content';
31+
import {MatAccordion} from './accordion';
3332
import {matExpansionAnimations} from './expansion-animations';
33+
import {MatExpansionPanelContent} from './expansion-panel-content';
3434

3535

3636
/** MatExpansionPanel's states. */
@@ -72,16 +72,6 @@ export class MatExpansionPanel extends CdkAccordionItem
7272
}
7373
private _hideToggle = false;
7474

75-
/** The positioning of the expansion indicator. */
76-
@Input()
77-
get togglePosition(): MatAccordionTogglePosition {
78-
return this.accordion ? this.accordion.togglePosition : this._togglePosition;
79-
}
80-
set togglePosition(position: MatAccordionTogglePosition) {
81-
this._togglePosition = position;
82-
}
83-
private _togglePosition: MatAccordionTogglePosition = 'after';
84-
8575
/** Stream that emits for changes in `@Input` properties. */
8676
readonly _inputChanges = new Subject<SimpleChanges>();
8777

src/lib/expansion/expansion.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ header to align with Material Design specifications.
1515

1616
By default, the expansion-panel header includes a toggle icon at the end of the
1717
header to indicate the expansion state. This icon can be hidden via the
18-
`hideToggle` property. The icon's position can also be configured with the `togglePosition`
19-
property.
18+
`hideToggle` property.
2019

2120
```html
2221
<mat-expansion-panel>

0 commit comments

Comments
 (0)