Skip to content

Commit 9c2331f

Browse files
allan-chencopybara-github
authored andcommitted
fix(linear-progress): disable animations when closed
PiperOrigin-RevId: 331803507
1 parent ed6b866 commit 9c2331f

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4141
- removed aria-hidden="true" from button
4242
- `linear-progress`
4343
- Fixed performance issues with indeterminate set on modern browsers
44+
- Animations no longer run when indicator has been closed.
4445

4546
## [v0.18.0] - 2020-08-03
4647

packages/linear-progress/mwc-linear-progress-base.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class LinearProgressBase extends LitElement {
4141
@internalProperty() protected styleSecondaryHalf = '';
4242
@internalProperty() protected styleSecondaryFull = '';
4343
@internalProperty() protected animationReady = true;
44-
44+
@internalProperty() protected closedAnimationOff = false;
4545
protected resizeObserver: ResizeObserver|null = null;
4646

4747
connectedCallback() {
@@ -59,6 +59,7 @@ export class LinearProgressBase extends LitElement {
5959
/** @classMap */
6060
const classes = {
6161
'mdc-linear-progress--closed': this.closed,
62+
'mdc-linear-progress--closed-animation-off': this.closedAnimationOff,
6263
'mdc-linear-progress--indeterminate': this.indeterminate,
6364
'mdc-linear-progress--reversed': this.reverse,
6465
// needed for controller-less render
@@ -101,7 +102,8 @@ export class LinearProgressBase extends LitElement {
101102
aria-valuemin="0"
102103
aria-valuemax="1"
103104
aria-valuenow=${
104-
ifDefined(this.indeterminate ? undefined : this.progress)}>
105+
ifDefined(this.indeterminate ? undefined : this.progress)}
106+
@transitionend=${this.syncClosedState}>
105107
<div class="mdc-linear-progress__buffer">
106108
<div
107109
class="mdc-linear-progress__buffer-bar"
@@ -120,12 +122,29 @@ export class LinearProgressBase extends LitElement {
120122
</div>`;
121123
}
122124

125+
update(changedProperties: Map<string, string>) {
126+
// - When showing the indicator, enable animations immediately.
127+
// - On first render, disable the animation immediately.
128+
// - For normal calls to hide the component, let transitionend event trigger
129+
// disabling of animations instead (see render method), so that animation
130+
// does not jump in the middle of fade out.
131+
if (changedProperties.has('closed') &&
132+
(!this.closed || changedProperties.get('closed') === undefined)) {
133+
this.syncClosedState();
134+
}
135+
super.update(changedProperties);
136+
}
137+
123138
async firstUpdated(changed: PropertyValues) {
124139
super.firstUpdated(changed);
125140

126141
this.attachResizeObserver();
127142
}
128143

144+
private syncClosedState() {
145+
this.closedAnimationOff = this.closed;
146+
}
147+
129148
protected updated(changed: PropertyValues) {
130149
// restart animation for timing if reverse changed and is indeterminate.
131150
// don't restart here if indeterminate has changed as well because we don't

packages/linear-progress/test/mwc-linear-progress.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,18 @@ suite('mwc-linear-progress', () => {
427427
HTMLElement;
428428
assert.isNotNull(root);
429429

430+
await element.updateComplete;
430431
assert.isTrue(root.classList.contains('mdc-linear-progress--closed'));
432+
assert.isTrue(
433+
root.classList.contains('mdc-linear-progress--closed-animation-off'));
431434

432435
element.closed = false;
433436

434437
await element.updateComplete;
435438

436439
assert.isFalse(root.classList.contains('mdc-linear-progress--closed'));
440+
assert.isFalse(
441+
root.classList.contains('mdc-linear-progress--closed-animation-off'));
437442
});
438443

439444
test('open, close methods set the correct classes', async () => {

0 commit comments

Comments
 (0)