Skip to content

Commit 10d4dff

Browse files
committed
fix(progress-bar): query animation not working on safari
Fixes the query animation not working on Safari. The issue comes from the fact that Safari won't resolve references correctly when the page has a `base` tag (which is required by `@angular/router`).
1 parent 444fb38 commit 10d4dff

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/lib/progress-bar/progress-bar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<circle cx="2.5" cy="2.5" r="2.5"/>
99
</pattern>
1010
</defs>
11-
<rect [attr.fill]="'url(#' + progressbarId + ')'" width="100%" height="100%"/>
11+
<rect [attr.fill]="'url(' + _currentPath + '#' + progressbarId + ')'" width="100%" height="100%"/>
1212
</svg>
1313
<div class="mat-progress-bar-buffer mat-progress-bar-element" [ngStyle]="_bufferTransform()"></div>
1414
<div class="mat-progress-bar-primary mat-progress-bar-fill mat-progress-bar-element" [ngStyle]="_primaryTransform()"></div>

src/lib/progress-bar/progress-bar.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {TestBed, async, ComponentFixture} from '@angular/core/testing';
22
import {Component} from '@angular/core';
33
import {By} from '@angular/platform-browser';
4+
import {Location} from '@angular/common';
45
import {MatProgressBarModule} from './index';
56

67

78
describe('MatProgressBar', () => {
9+
let fakePath = '/fake-path';
810

911
beforeEach(async(() => {
1012
TestBed.configureTestingModule({
@@ -13,6 +15,10 @@ describe('MatProgressBar', () => {
1315
BasicProgressBar,
1416
BufferProgressBar,
1517
],
18+
providers: [{
19+
provide: Location,
20+
useValue: {path: () => fakePath}
21+
}]
1622
});
1723

1824
TestBed.compileComponents();
@@ -88,6 +94,11 @@ describe('MatProgressBar', () => {
8894
expect(progressComponent._bufferTransform()).toEqual({transform: 'scaleX(0.6)'});
8995
});
9096

97+
it('should prefix SVG references with the current path', () => {
98+
const rect = fixture.debugElement.query(By.css('rect')).nativeElement;
99+
expect(rect.getAttribute('fill')).toMatch(/^url\(\/fake-path#.*\)$/);
100+
});
101+
91102
it('should not be able to tab into the underlying SVG element', () => {
92103
const svg = fixture.debugElement.query(By.css('svg')).nativeElement;
93104
expect(svg.getAttribute('focusable')).toBe('false');

src/lib/progress-bar/progress-bar.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Optional,
1515
ViewEncapsulation
1616
} from '@angular/core';
17+
import {Location} from '@angular/common';
1718
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
1819
import {CanColor, mixinColor} from '@angular/material/core';
1920

@@ -54,11 +55,21 @@ let progressbarId = 0;
5455
encapsulation: ViewEncapsulation.None,
5556
})
5657
export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor {
57-
58+
/**
59+
* Current page path. Used to prefix SVG references which
60+
* won't work on Safari unless they're prefixed with the path.
61+
*/
62+
_currentPath: string;
5863

5964
constructor(public _elementRef: ElementRef,
60-
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
65+
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string,
66+
/**
67+
* @deprecated `location` parameter to be made required.
68+
* @deletion-target 8.0.0
69+
*/
70+
location?: Location) {
6171
super(_elementRef);
72+
this._currentPath = location ? location.path() : '';
6273
}
6374

6475
/** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */

0 commit comments

Comments
 (0)