Skip to content

fix(progress-spinner): circle not rendering correctly when switching modes in Safari #12151

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

Merged
merged 1 commit into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/progress-spinner/progress-spinner-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {MatCommonModule} from '@angular/material/core';
import {MatProgressSpinner, MatSpinner} from './progress-spinner';


@NgModule({
imports: [MatCommonModule],
imports: [MatCommonModule, CommonModule],
exports: [
MatProgressSpinner,
MatSpinner,
Expand Down
20 changes: 19 additions & 1 deletion src/lib/progress-spinner/progress-spinner.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,32 @@
[style.height.px]="diameter"
[attr.viewBox]="_viewBox"
preserveAspectRatio="xMidYMid meet"
focusable="false">
focusable="false"
[ngSwitch]="mode === 'indeterminate'">

<!--
Technically we can reuse the same `circle` element, however Safari has an issue that breaks
the SVG rendering in determinate mode, after switching between indeterminate and determinate.
Using a different element avoids the issue. An alternative to this is adding `display: none`
for a split second and then removing it when switching between modes, but it's hard to know
for how long to hide the element and it can cause the UI to blink.
-->
<circle
*ngSwitchCase="true"
cx="50%"
cy="50%"
[attr.r]="_circleRadius"
[style.animation-name]="'mat-progress-spinner-stroke-rotate-' + diameter"
[style.stroke-dashoffset.px]="_strokeDashOffset"
[style.stroke-dasharray.px]="_strokeCircumference"
[style.stroke-width.%]="_circleStrokeWidth"></circle>

<circle
*ngSwitchCase="false"
cx="50%"
cy="50%"
[attr.r]="_circleRadius"
[style.stroke-dashoffset.px]="_strokeDashOffset"
[style.stroke-dasharray.px]="_strokeCircumference"
[style.stroke-width.%]="_circleStrokeWidth"></circle>
</svg>
23 changes: 21 additions & 2 deletions src/lib/progress-spinner/progress-spinner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ describe('MatProgressSpinner', () => {
expect(progressElement.componentInstance.value).toBe(75);
});

it('should use different `circle` elements depending on the mode', () => {
const fixture = TestBed.createComponent(ProgressSpinnerWithValueAndBoundMode);

fixture.componentInstance.mode = 'determinate';
fixture.detectChanges();

const determinateCircle = fixture.nativeElement.querySelector('circle');

fixture.componentInstance.mode = 'indeterminate';
fixture.detectChanges();

const indeterminateCircle = fixture.nativeElement.querySelector('circle');

expect(determinateCircle).toBeTruthy();
expect(indeterminateCircle).toBeTruthy();
expect(determinateCircle).not.toBe(indeterminateCircle);
});

it('should clamp the value of the progress between 0 and 100', () => {
let fixture = TestBed.createComponent(BasicProgressSpinner);
fixture.detectChanges();
Expand Down Expand Up @@ -138,12 +156,13 @@ describe('MatProgressSpinner', () => {

it('should allow a custom stroke width', () => {
const fixture = TestBed.createComponent(ProgressSpinnerCustomStrokeWidth);
const circleElement = fixture.nativeElement.querySelector('circle');
const svgElement = fixture.nativeElement.querySelector('svg');

fixture.componentInstance.strokeWidth = 40;
fixture.detectChanges();

const circleElement = fixture.nativeElement.querySelector('circle');
const svgElement = fixture.nativeElement.querySelector('svg');

expect(parseInt(circleElement.style.strokeWidth)).toBe(40, 'Expected the custom stroke ' +
'width to be applied to the circle element as a percentage of the element size.');
expect(svgElement.getAttribute('viewBox'))
Expand Down