From e21c70f17e0564de414787ac808b3a98a3672c53 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Tue, 24 Jul 2018 21:50:39 +0200 Subject: [PATCH] fix(progress-bar): query animation not working inside routes with named outlets This is something that was introduced by #12014. Because we didn't have quotes around the URL in the `fill` value, the reference could become invalid if the user is on a route with a named outlet, which contains parentheses in its URL. Fixes #12338. --- src/lib/progress-bar/progress-bar.html | 2 +- src/lib/progress-bar/progress-bar.spec.ts | 2 +- src/lib/progress-bar/progress-bar.ts | 17 +++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib/progress-bar/progress-bar.html b/src/lib/progress-bar/progress-bar.html index 642428d02e42..76b0f9575bdf 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 d4279137615d..883cbe13dc3e 100644 --- a/src/lib/progress-bar/progress-bar.spec.ts +++ b/src/lib/progress-bar/progress-bar.spec.ts @@ -96,7 +96,7 @@ describe('MatProgressBar', () => { 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#.*\)$/); + expect(rect.getAttribute('fill')).toMatch(/^url\(['"]?\/fake-path#.*['"]?\)$/); }); it('should not be able to tab into the underlying SVG element', () => { diff --git a/src/lib/progress-bar/progress-bar.ts b/src/lib/progress-bar/progress-bar.ts index bfde01c66c85..5124cd55b3cd 100644 --- a/src/lib/progress-bar/progress-bar.ts +++ b/src/lib/progress-bar/progress-bar.ts @@ -55,12 +55,6 @@ 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, /** @@ -69,7 +63,11 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor */ @Optional() location?: Location) { super(_elementRef); - this._currentPath = location ? location.path() : ''; + + // We need to prefix the SVG reference with the current path, otherwise they won't work + // in Safari if the page has a `` tag. Note that we need quotes inside the `url()`, + // because named route URLs can contain parentheses (see #12338). + this._rectangleFillValue = `url('${location ? location.path() : ''}#${this.progressbarId}')`; } /** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */ @@ -93,9 +91,12 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor */ @Input() mode: 'determinate' | 'indeterminate' | 'buffer' | 'query' = 'determinate'; - /** The id of the progress bar. */ + /** ID of the progress bar. */ progressbarId = `mat-progress-bar-${progressbarId++}`; + /** Attribute to be used for the `fill` attribute on the internal `rect` element. */ + _rectangleFillValue: string; + /** Gets the current transform value for the progress bar's primary indicator. */ _primaryTransform() { const scale = this.value / 100;