Skip to content

Commit b9c0d85

Browse files
crisbetommalerba
authored andcommitted
fix(progress-bar): query animation not working inside routes with named outlets (#12350)
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.
1 parent e2a158e commit b9c0d85

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
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(' + _currentPath + '#' + progressbarId + ')'" width="100%" height="100%"/>
11+
<rect [attr.fill]="_rectangleFillValue" 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('MatProgressBar', () => {
9696

9797
it('should prefix SVG references with the current path', () => {
9898
const rect = fixture.debugElement.query(By.css('rect')).nativeElement;
99-
expect(rect.getAttribute('fill')).toMatch(/^url\(\/fake-path#.*\)$/);
99+
expect(rect.getAttribute('fill')).toMatch(/^url\(['"]?\/fake-path#.*['"]?\)$/);
100100
});
101101

102102
it('should not be able to tab into the underlying SVG element', () => {

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ let progressbarId = 0;
5555
encapsulation: ViewEncapsulation.None,
5656
})
5757
export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor {
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;
63-
6458
constructor(public _elementRef: ElementRef,
6559
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string,
6660
/**
@@ -69,7 +63,11 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor
6963
*/
7064
@Optional() location?: Location) {
7165
super(_elementRef);
72-
this._currentPath = location ? location.path() : '';
66+
67+
// We need to prefix the SVG reference with the current path, otherwise they won't work
68+
// in Safari if the page has a `<base>` tag. Note that we need quotes inside the `url()`,
69+
// because named route URLs can contain parentheses (see #12338).
70+
this._rectangleFillValue = `url('${location ? location.path() : ''}#${this.progressbarId}')`;
7371
}
7472

7573
/** Value of the progress bar. Defaults to zero. Mirrored to aria-valuenow. */
@@ -93,9 +91,12 @@ export class MatProgressBar extends _MatProgressBarMixinBase implements CanColor
9391
*/
9492
@Input() mode: 'determinate' | 'indeterminate' | 'buffer' | 'query' = 'determinate';
9593

96-
/** The id of the progress bar. */
94+
/** ID of the progress bar. */
9795
progressbarId = `mat-progress-bar-${progressbarId++}`;
9896

97+
/** Attribute to be used for the `fill` attribute on the internal `rect` element. */
98+
_rectangleFillValue: string;
99+
99100
/** Gets the current transform value for the progress bar's primary indicator. */
100101
_primaryTransform() {
101102
const scale = this.value / 100;

0 commit comments

Comments
 (0)