-
Notifications
You must be signed in to change notification settings - Fork 914
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
copybara-service
merged 6 commits into
material-components:main
from
datvm:linear-progress-buffer
Feb 22, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8fa444c
fix(progress): progress buffer defaults to negative.
datvm e4b8ef5
Added null check for buffer (due to possibility of attribute removal)
datvm 1e1048a
Merge branch 'main' into linear-progress-buffer
datvm a8a9d56
Buffer default value is now 0 and added some code cleanup.
datvm 2512f55
Removed linear progress buffer clamping
datvm c7e26b5
Added back the buffer check vs. max value
datvm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
*/ | ||
@property({type: Number}) buffer = 1; | ||
@property({type: Number}) buffer = -1; | ||
|
||
// Note, the indeterminate animation is rendered with transform %'s | ||
// Previously, this was optimized to use px calculated with the resizeObserver | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
||
return html` | ||
<div class="dots" ?hidden=${hideDots}></div> | ||
<div class="inactive-track" style=${styleMap(dotStyles)}></div> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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