Skip to content
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

fix(progress-bar): query animation not working inside routes with named outlets #12350

Merged
merged 1 commit into from Jul 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/progress-bar/progress-bar.html
Expand Up @@ -8,7 +8,7 @@
<circle cx="2.5" cy="2.5" r="2.5"/>
</pattern>
</defs>
<rect [attr.fill]="'url(' + _currentPath + '#' + progressbarId + ')'" width="100%" height="100%"/>
<rect [attr.fill]="_rectangleFillValue" width="100%" height="100%"/>
</svg>
<div class="mat-progress-bar-buffer mat-progress-bar-element" [ngStyle]="_bufferTransform()"></div>
<div class="mat-progress-bar-primary mat-progress-bar-fill mat-progress-bar-element" [ngStyle]="_primaryTransform()"></div>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/progress-bar/progress-bar.spec.ts
Expand Up @@ -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', () => {
Expand Down
17 changes: 9 additions & 8 deletions src/lib/progress-bar/progress-bar.ts
Expand Up @@ -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,
/**
Expand All @@ -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 `<base>` 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. */
Expand All @@ -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;
Expand Down