Skip to content

Commit a706c8c

Browse files
josephperrottvivian-hu-zz
authored andcommitted
fix(expansion-panel): correct jump in panel sizing during animation (#12509)
1 parent 0060bd7 commit a706c8c

File tree

4 files changed

+4
-38
lines changed

4 files changed

+4
-38
lines changed

src/lib/expansion/expansion-panel.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
role="region"
44
[@bodyExpansion]="_getExpandedState()"
55
(@bodyExpansion.done)="_bodyAnimation($event)"
6-
(@bodyExpansion.start)="_bodyAnimation($event)"
76
[attr.aria-labelledby]="_headerId"
87
[id]="id"
98
#body>

src/lib/expansion/expansion-panel.scss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
display: block;
1010
margin: 0;
1111
border-radius: $border-radius;
12+
overflow: hidden;
1213
transition: margin 225ms $mat-fast-out-slow-in-timing-function,
1314
mat-elevation-transition-property-value();
1415

@@ -40,11 +41,9 @@
4041
}
4142

4243
.mat-expansion-panel-content {
43-
overflow: hidden;
44-
45-
&.mat-expanded {
46-
overflow: visible;
47-
}
44+
display: flex;
45+
flex-direction: column;
46+
overflow: visible;
4847
}
4948

5049
.mat-expansion-panel-body {

src/lib/expansion/expansion-panel.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,8 @@ export class MatExpansionPanel extends CdkAccordionItem implements AfterContentI
170170
}
171171

172172
_bodyAnimation(event: AnimationEvent) {
173-
const classList = event.element.classList;
174-
const cssClass = 'mat-expanded';
175173
const {phaseName, toState, fromState} = event;
176174

177-
// Toggle the body's `overflow: hidden` class when closing starts or when expansion ends in
178-
// order to prevent the cases where switching too early would cause the animation to jump.
179-
// Note that we do it directly on the DOM element to avoid the slight delay that comes
180-
// with doing it via change detection.
181-
if (phaseName === 'done' && toState === 'expanded') {
182-
classList.add(cssClass);
183-
}
184-
if (phaseName === 'start' && toState === 'collapsed') {
185-
classList.remove(cssClass);
186-
}
187-
188175
if (phaseName === 'done' && toState === 'expanded' && fromState !== 'void') {
189176
this.afterExpand.emit();
190177
}

src/lib/expansion/expansion.spec.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,16 @@ describe('MatExpansionPanel', () => {
2828

2929
it('should expand and collapse the panel', fakeAsync(() => {
3030
const fixture = TestBed.createComponent(PanelWithContent);
31-
const contentEl = fixture.nativeElement.querySelector('.mat-expansion-panel-content');
3231
const headerEl = fixture.nativeElement.querySelector('.mat-expansion-panel-header');
3332
fixture.detectChanges();
3433

3534
expect(headerEl.classList).not.toContain('mat-expanded');
36-
expect(contentEl.classList).not.toContain('mat-expanded');
3735

3836
fixture.componentInstance.expanded = true;
3937
fixture.detectChanges();
4038
flush();
4139

4240
expect(headerEl.classList).toContain('mat-expanded');
43-
expect(contentEl.classList).toContain('mat-expanded');
4441
}));
4542

4643
it('should be able to render panel content lazily', fakeAsync(() => {
@@ -267,23 +264,7 @@ describe('MatExpansionPanel', () => {
267264
expect(fixture.componentInstance.expanded).toBe(false);
268265
});
269266

270-
it('should not set the mat-expanded class until the open animation is done', fakeAsync(() => {
271-
const fixture = TestBed.createComponent(PanelWithContent);
272-
const contentEl = fixture.nativeElement.querySelector('.mat-expansion-panel-content');
273-
274-
fixture.detectChanges();
275-
expect(contentEl.classList).not.toContain('mat-expanded',
276-
'Expected class not to be there on init');
277-
278-
fixture.componentInstance.expanded = true;
279-
fixture.detectChanges();
280-
expect(contentEl.classList).not.toContain('mat-expanded',
281-
'Expected class not to be added immediately after becoming expanded');
282267

283-
flush();
284-
expect(contentEl.classList).toContain('mat-expanded',
285-
'Expected class to be added after the animation has finished');
286-
}));
287268

288269
it('should emit events for body expanding and collapsing animations', fakeAsync(() => {
289270
const fixture = TestBed.createComponent(PanelWithContent);

0 commit comments

Comments
 (0)