Skip to content

Commit 43ba9d9

Browse files
committed
fix(material-experimental/slider): incorrectly rendering extra background
Currently the slider always has the `mdc-slider--display-markers` class which causes an extra background to be rendered on sliders without markers. Since it's incorrect, these changes only add the class when markers are supposed to be rendered.
1 parent 7cd78ff commit 43ba9d9

File tree

1 file changed

+7
-5
lines changed
  • src/material-experimental/mdc-slider

1 file changed

+7
-5
lines changed

src/material-experimental/mdc-slider/slider.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,15 @@ export class MatSliderChange {
7777
templateUrl: 'slider.html',
7878
styleUrls: ['slider.css'],
7979
host: {
80-
// The standard Angular Material slider has the capability to dynamically toggle
81-
// whether tick markers should show or not. Therefore we need to make sure that
82-
// the MDC slider foundation is able to render tick markers. We dynamically toggle
83-
// them based on the specified "tickInterval" input.
84-
'class': 'mat-mdc-slider mdc-slider mdc-slider--display-markers',
80+
'class': 'mat-mdc-slider mdc-slider',
8581
'role': 'slider',
8682
'aria-orientation': 'horizontal',
8783
// The tabindex if the slider turns disabled is managed by the MDC foundation which
8884
// dynamically updates and restores the "tabindex" attribute.
8985
'[attr.tabindex]': 'tabIndex || 0',
9086
'[class.mdc-slider--discrete]': 'thumbLabel',
9187
'[class.mat-slider-has-ticks]': 'tickInterval !== 0',
88+
'[class.mdc-slider--display-markers]': 'tickInterval !== 0',
9289
'[class.mat-slider-thumb-label-showing]': 'thumbLabel',
9390
'[class.mat-slider-disabled]': 'disabled',
9491
'[class.mat-primary]': 'color == "primary"',
@@ -464,6 +461,11 @@ export class MatSlider implements AfterViewInit, OnChanges, OnDestroy, ControlVa
464461

465462
/** Method that ensures that track markers are refreshed. */
466463
private _refreshTrackMarkers() {
464+
// MDC only checks whether the slider has markers once on init by looking for the
465+
// `mdc-slider--display-markers` class in the DOM, whereas we support changing and hiding
466+
// the markers dynamically. This is a workaround until we can get a public API for it. See:
467+
// https://github.com/material-components/material-components-web/issues/5020
468+
(this._foundation as any).hasTrackMarker_ = this.tickInterval !== 0;
467469
this._foundation.setupTrackMarker();
468470
}
469471

0 commit comments

Comments
 (0)