-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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-spinner): element size not updated when diamater is changed #8697
Conversation
Hi, thanks for taking the time to send a PR! This change would cause the browser to potentially trigger a re-layout on every change detection cycle, which is something we would want to avoid since it could hurt application performance. The right approach would be to have the component mark itself as needing change detection when the diameter changes. |
Hi @jelbourn thanks for the feedback. I tried to use the methods After some research, I found this stackoverflow question. And it seems that the change detection will not work for input without bindings. You said that this change can trigger a re-layout on every detection cycle, but the elementSize is only recalculated when the changes are for strokeWidth or diamter properties. Is there a way to check this behavior ? |
@crisbeto can you take a look at this PR? |
const fixture = TestBed.createComponent(MatProgressSpinner); | ||
const spinner = fixture.componentInstance; | ||
spinner.diameter = 32; | ||
expect(spinner._elementSize).toBe(32); |
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.
Can you test the styles that are applied to the element, rather than the property itself? You can look at how the other tests are doing it.
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ |
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.
Can you remove this license banner? There is one already at the top of the file.
@@ -231,6 +240,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements | |||
.replace(/END_VALUE/g, `${0.2 * this._strokeCircumference}`) | |||
.replace(/DIAMETER/g, `${this.diameter}`); | |||
} | |||
|
|||
/**Updates the spinner element size based on its diameter */ |
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.
Needs a space after the /**
and a dot at the end of the sentence.
@@ -231,6 +240,11 @@ export class MatProgressSpinner extends _MatProgressSpinnerMixinBase implements | |||
.replace(/END_VALUE/g, `${0.2 * this._strokeCircumference}`) | |||
.replace(/DIAMETER/g, `${this.diameter}`); | |||
} | |||
|
|||
/**Updates the spinner element size based on its diameter */ | |||
private _updateSpinnerDimension() { |
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.
Rename to _updateElementSize
.
3272b58
to
110c5e4
Compare
@crisbeto comments addressed ! 👍 |
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.
LGTM, one last nit: can you rename the commit and PR to something like "fix(progress-spinner): element size not updated when diamater is changed"?
110c5e4
to
2c46960
Compare
@crisbeto Sure, changes done ! |
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.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Updating the diameter property programmatically don't trigger the ngOnChanges events.
This change updates the code to calculate the _elementSize property on diameter change