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(material/progress-spinner): progress-spinners with diameter less than or equal to 10 do not show #20062

Closed

Conversation

AlexLangdon
Copy link
Contributor

@AlexLangdon AlexLangdon commented Jul 21, 2020

As @paulferaud pointed out in #19469, using BASE_STROKE_WIDTH when calculating the spinner circle radius is causing issues, such as the progress spinner becoming invisible if the diameter is less than or equal to 10.

The proposed solution is to use the current stroke width instead of the BASE_STROKE_WIDTH constant for calculating the spinner radius.

This one change will also stop the spinner circle extending beyond its parent mat-progress-spinner dimensions for custom stroke widths (see screenshot and stackblitz below), which I presume is an improvement.

https://stackblitz.com/edit/components-issue-jsceqa?file=src%2Fapp%2Fexample-component.html

Before commit:
issue-19469-before

After commit:
issue-19469-after

Fixes #19469

…than or equal to 10 do not show

Fixes a bug in the Angular Material ‘progress-spinner’ component
where progress-spinners with a diameter less than or equal to 10
do not show. This is because the spinner radius calculation uses
a constant stroke width of 10 instead of the current stroke width.

Fixes angular#19469
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 21, 2020
* Base reference stroke width of the spinner.
* @docs-private
*/
const BASE_STROKE_WIDTH = 10;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intention behind using BASE_STROKE_WIDTH constant isn't yet apparent to me, given it is not used anywhere else. Maybe it worked for a spinner with a default diameter and stroke width?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decided to keep BASE_STROKE_WIDTH for use in calculating the base circle diameter.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

If I remember correctly, we need the base stroke, because it's hardcoded to the default animation that's inside the CSS and changing it to something different will break it. See:
demo

I think the underlying problem here is that the dynamically-inserted style tags with the new animation are keyed only on the diameter, not the circumference which is what determines how the animation looks and accounts both for the diameter and the stroke. I don't remember whether we did it this way because the logic breaks down at some point, or we just didn't think that it was important. It wouldn't hurt changing it and testing it out though.

@AlexLangdon
Copy link
Contributor Author

If I remember correctly, we need the base stroke, because it's hardcoded to the default animation that's inside the CSS and changing it to something different will break it. See:
demo

I think the underlying problem here is that the dynamically-inserted style tags with the new animation are keyed only on the diameter, not the circumference which is what determines how the animation looks and accounts both for the diameter and the stroke. I don't remember whether we did it this way because the logic breaks down at some point, or we just didn't think that it was important. It wouldn't hurt changing it and testing it out though.

Thanks for pointing that out, hadn't checked that case earlier. I will see if I can find the cause of this animation issue.

@AlexLangdon
Copy link
Contributor Author

@crisbeto

Based on your suggestion I found an issue with using floating point circumference values in animation names. The animation-name property does not support periods (https://developer.mozilla.org/en-US/docs/Web/CSS/animation-name), so just appending the circumference to the end of the animation name e.g. “animation-name-90.6” would be invalid.

It should be noted that this is also a problem in the current code, if a floating point diameter is given for the spinner - see https://stackblitz.com/edit/components-issue-dxxhqv?file=src%2Fapp%2Fexample-component.html

To get around this, I have replaced “.” characters with “_” in the circle diameter appended to the animation name e.g. “animation-name-90_6” instead of “animation-name-90.6”.

This should solve the animation issue mentioned above, along with allowing floating point numbers to be used for the stroke width and diameter, which I assume is preferable. The fixes mentioned in my first comment regarding diameter <= 10 and the circle element extending beyond its parents are also maintained.

Happy to hear feedback on if/how float input values should be handled here.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

Something to keep in mind: even though the changes to the circle sizing are correct, they might make the PR harder to land, because they'll break people's screenshot tests.

/** Returns a string that is used for setting the spinner animation-name CSS property */
get _spinnerAnimationLabel() {
// Period '.' character cannot be included in an animation-name
return this._circleDiameter.toString().replace('.', '_');
Copy link
Member

Choose a reason for hiding this comment

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

This will be called on every change detection run, but it only changes when the diameter is changed. It might be better if we used a regular property that gets updated once per input change.

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, missed this one. Updated the PR with the corrections.

…than or equal to 10 do not show

Binds the spinner rotate animation name to the circle element diameter, thereby
fixing broken spinner animations introduced in the previous commit.
Allows float point values to be used for custom diameter and stroke width.

Fixes angular#19469
AlexLangdon and others added 2 commits July 29, 2020 01:26
…than or equal to 10 do not show

Correcting circle diameter getter usage and public api definition.

Fixes angular#19469
@AlexLangdon
Copy link
Contributor Author

AlexLangdon commented Jul 29, 2020

Something to keep in mind: even though the changes to the circle sizing are correct, they might make the PR harder to land, because they'll break people's screenshot tests.

Would it be preferable to split this into separate PRs? Keep this PR just for supporting diameters of <= 10 along with float values, which should not break many screenshot tests as it is adding support for a larger range of inputs. I can open a separate issue with another PR to correct the circle radius calculation relative to current stroke width.

@crisbeto
Copy link
Member

Yes, it would be easier to get it merged in as separate PRs.

@AlexLangdon
Copy link
Contributor Author

Opened PRs #20193 and #20192, which fix spinner issues with diameter <= 10 (#19469) and floating point diameters respectively (#20158), and shouldn't add breaking changes.

Right now, I can’t see a neat alternative that corrects the spinner radius calculation (#20159) but does not fix both of the above issues or potentially break screenshot tests as a result.

Closing this PR in favour of an updated version #20289.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(MatProgressSpinner): Small Spinners with diameter <= 10 don’t show
3 participants