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 on safari #12014

Merged
merged 1 commit into from
Jul 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/progress-bar/progress-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<circle cx="2.5" cy="2.5" r="2.5"/>
</pattern>
</defs>
<rect [attr.fill]="'url(#' + progressbarId + ')'" width="100%" height="100%"/>
<rect [attr.fill]="'url(' + _currentPath + '#' + progressbarId + ')'" 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
11 changes: 11 additions & 0 deletions src/lib/progress-bar/progress-bar.spec.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -13,6 +15,10 @@ describe('MatProgressBar', () => {
BasicProgressBar,
BufferProgressBar,
],
providers: [{
provide: Location,
useValue: {path: () => fakePath}
}]
});

TestBed.compileComponents();
Expand Down Expand Up @@ -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');
Expand Down
15 changes: 13 additions & 2 deletions src/lib/progress-bar/progress-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
*/
@Optional() location?: Location) {
super(_elementRef);
this._currentPath = location ? location.path() : '';
}

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