Skip to content

fix(slider): track fill not rendering on ios safari when slider starts at 0 #17583

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

Merged
merged 1 commit into from
Nov 11, 2019
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
9 changes: 9 additions & 0 deletions src/material/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ describe('MatSlider', () => {
expect(trackFillElement.style.transform).toContain('scale3d(0.39, 1, 1)');
});

it('should hide the fill element at zero percent', () => {
expect(trackFillElement.style.display).toBe('none');

dispatchMousedownEventSequence(sliderNativeElement, 0.39);
fixture.detectChanges();

expect(trackFillElement.style.display).toBeFalsy();
});

it('should update the track fill on slide', () => {
expect(trackFillElement.style.transform).toContain('scale3d(0, 1, 1)');

Expand Down
10 changes: 8 additions & 2 deletions src/material/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,19 @@ export class MatSlider extends _MatSliderMixinBase

/** CSS styles for the track fill element. */
get _trackFillStyles(): { [key: string]: string } {
const percent = this.percent;
const axis = this.vertical ? 'Y' : 'X';
const scale = this.vertical ? `1, ${this.percent}, 1` : `${this.percent}, 1, 1`;
const scale = this.vertical ? `1, ${percent}, 1` : `${percent}, 1, 1`;
const sign = this._shouldInvertMouseCoords() ? '' : '-';

return {
// scale3d avoids some rendering issues in Chrome. See #12071.
transform: `translate${axis}(${sign}${this._thumbGap}px) scale3d(${scale})`
transform: `translate${axis}(${sign}${this._thumbGap}px) scale3d(${scale})`,
// iOS Safari has a bug where it won't re-render elements which start of as `scale(0)` until
// something forces a style recalculation on it. Since we'll end up with `scale(0)` when
// the value of the slider is 0, we can easily get into this situation. We force a
// recalculation by changing the element's `display` when it goes from 0 to any other value.
display: percent === 0 ? 'none' : ''
};
}

Expand Down