From 10d4dffb3db979912c1d0f901cbdbffde1d1aa85 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Mon, 2 Jul 2018 14:25:14 +0200 Subject: [PATCH] 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`). --- src/lib/progress-bar/progress-bar.html | 2 +- src/lib/progress-bar/progress-bar.spec.ts | 11 +++++++++++ src/lib/progress-bar/progress-bar.ts | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/lib/progress-bar/progress-bar.html b/src/lib/progress-bar/progress-bar.html index b4e66c5b6575..642428d02e42 100644 --- a/src/lib/progress-bar/progress-bar.html +++ b/src/lib/progress-bar/progress-bar.html @@ -8,7 +8,7 @@ - +
diff --git a/src/lib/progress-bar/progress-bar.spec.ts b/src/lib/progress-bar/progress-bar.spec.ts index b5b0a6dde230..d4279137615d 100644 --- a/src/lib/progress-bar/progress-bar.spec.ts +++ b/src/lib/progress-bar/progress-bar.spec.ts @@ -1,10 +1,12 @@ import {TestBed, async, ComponentFixture} from '@angular/core/testing'; import {Component} from '@angular/core'; import {By} from '@angular/platform-browser'; +import {Location} from '@angular/common'; import {MatProgressBarModule} from './index'; describe('MatProgressBar', () => { + let fakePath = '/fake-path'; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -13,6 +15,10 @@ describe('MatProgressBar', () => { BasicProgressBar, BufferProgressBar, ], + providers: [{ + provide: Location, + useValue: {path: () => fakePath} + }] }); TestBed.compileComponents(); @@ -88,6 +94,11 @@ describe('MatProgressBar', () => { expect(progressComponent._bufferTransform()).toEqual({transform: 'scaleX(0.6)'}); }); + it('should prefix SVG references with the current path', () => { + const rect = fixture.debugElement.query(By.css('rect')).nativeElement; + expect(rect.getAttribute('fill')).toMatch(/^url\(\/fake-path#.*\)$/); + }); + it('should not be able to tab into the underlying SVG element', () => { const svg = fixture.debugElement.query(By.css('svg')).nativeElement; expect(svg.getAttribute('focusable')).toBe('false'); diff --git a/src/lib/progress-bar/progress-bar.ts b/src/lib/progress-bar/progress-bar.ts index d12f50243daf..002da4e4d944 100644 --- a/src/lib/progress-bar/progress-bar.ts +++ b/src/lib/progress-bar/progress-bar.ts @@ -14,6 +14,7 @@ import { Optional, ViewEncapsulation } from '@angular/core'; +import {Location} from '@angular/common'; import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations'; import {CanColor, mixinColor} from '@angular/material/core'; @@ -54,11 +55,21 @@ let progressbarId = 0; encapsulation: ViewEncapsulation.None, }) export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor { - + /** + * Current page path. Used to prefix SVG references which + * won't work on Safari unless they're prefixed with the path. + */ + _currentPath: string; constructor(public _elementRef: ElementRef, - @Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) { + @Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string, + /** + * @deprecated `location` parameter to be made required. + * @deletion-target 8.0.0 + */ + location?: Location) { super(_elementRef); + this._currentPath = location ? location.path() : ''; } /** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */