Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(progress): progress buffer defaults to 0 #5352

Merged

Conversation

datvm
Copy link
Contributor

@datvm datvm commented Dec 27, 2023

Fix #5251 .

    <md-linear-progress value="10" max="100"></md-linear-progress>    
    <md-linear-progress value="10" buffer="50" max="100"></md-linear-progress>

image

@datvm datvm changed the title fix(progress): progress buffer defaults to negative. fix(progress): progress buffer defaults to negative Dec 27, 2023
@datvm
Copy link
Contributor Author

datvm commented Feb 13, 2024

@asyncLiz hi, anything else for this PR?

Copy link
Collaborator

@asyncLiz asyncLiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the ping! I lost track of this.

@@ -30,14 +31,15 @@ export class LinearProgress extends Progress {
};
const dotStyles = {
transform: `scaleX(${
(this.indeterminate ? 1 : this.buffer / this.max) * 100
// == null is used to check for both null and undefined when buffer attribute is removed
(this.indeterminate || this.buffer == null || this.buffer < 0 ? 1 : this.buffer / this.max) * 100
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to get hard to grok, let's split it out and simplify it.

// use ?? for null and undefined when the buffer attribute is removed.
const bufferValue = this.buffer ?? 0;
const hasBuffer buffer > 0;
const dotSize = this.indeterminate || !hasBuffer ? 1 : bufferValue / this.max;
const dotStyles = {
  transform: `scaleX(${dotSize * 100}%)`
};

}%)`,
};

// Only display dots when visible - this prevents invisible infinite
// animation.
const hideDots =
this.indeterminate || this.buffer >= this.max || this.value >= this.max;
this.indeterminate || this.buffer == null || this.buffer < 0 || this.buffer >= this.max || this.value >= this.max;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And use the new variables here

const hideDots =
  this.indeterminate || !hasBuffer || bufferValue >= this.max || this.value >= this.max;

@@ -16,8 +16,9 @@ import {Progress} from './progress.js';
export class LinearProgress extends Progress {
/**
* Buffer amount to display, a fraction between 0 and `max`.
* If negative, the buffer is not displayed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, actually what about using 0 as the default value to indicate that there is no buffer? I think that makes more better sense than using negative to indicate it.

If there's 0 buffer after all, there is no buffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asyncLiz thanks, the latest commit should address the above suggestions

@@ -28,16 +29,20 @@ export class LinearProgress extends Progress {
(this.indeterminate ? 1 : this.value / this.max) * 100
}%)`,
};

const bufferValue = Math.min(this.buffer ?? 0, this.max);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I entirely follow why we need Math.min here to change bufferValue to max. Is it to avoid bufferValue >= this.max for const hideDots?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so we do not need to worry about that logic with dotStyles anymore though I suppose the hideDots would take care of it anyway right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I believe so. Do you mind not clamping it and keeping the bufferValue >= this.max check?

Semantically "bufferValue" as changed doesn't reflect this.buffer, it's really bufferValueOrMax. It's a bit confusing to read, and may inadvertently cause problems if future changes don't realize that nuance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asyncLiz sure I did in the last commit.

};

// Only display dots when visible - this prevents invisible infinite
// animation.
const hideDots =
this.indeterminate || this.buffer >= this.max || this.value >= this.max;
this.indeterminate || !hasBuffer || this.value >= this.max;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last change I think! We still need the max check, !hasBuffer || bufferValue >= this.max

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops 😬 sorry I forgot about that one after removing the previous one. It should be updated now.

@asyncLiz asyncLiz changed the title fix(progress): progress buffer defaults to negative fix(progress): progress buffer defaults to 0 Feb 21, 2024
@copybara-service copybara-service bot merged commit 2613de4 into material-components:main Feb 22, 2024
4 of 5 checks passed
@datvm datvm deleted the linear-progress-buffer branch March 5, 2024 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignore Linear Progress' Buffer unless it is set?
2 participants