Skip to content

build: update to latest MDC canary and disable slider #20054

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
Jul 21, 2020
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@types/youtube": "^0.0.38",
"@webcomponents/custom-elements": "^1.1.0",
"core-js": "^2.6.9",
"material-components-web": "8.0.0-canary.d850de590.0",
"material-components-web": "8.0.0-canary.abcdbcfeb.0",
"rxjs": "^6.5.3",
"rxjs-tslint-rules": "^4.33.1",
"systemjs": "0.19.43",
Expand Down
15 changes: 10 additions & 5 deletions src/material-experimental/mdc-slider/_slider-theme.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// TODO: disabled until we implement the new MDC slider.
// @import '@material/slider/mixins.import';
@import '../mdc-helpers/mdc-helpers';
@import '@material/slider/mixins.import';

@mixin mat-mdc-slider-color($config-or-theme) {
$config: mat-get-color-config($config-or-theme);
@include mat-using-mdc-theme($config) {
@include mdc-slider-core-styles($query: $mat-theme-styles-query);
// TODO: disabled until we implement the new MDC slider.
// @include mdc-slider-core-styles($query: $mat-theme-styles-query);

.mat-mdc-slider {
&.mat-primary {
@include mdc-slider-color-accessible(primary, $mat-theme-styles-query);
// TODO: disabled until we implement the new MDC slider.
// @include mdc-slider-color-accessible(primary, $mat-theme-styles-query);
}

&.mat-warn {
@include mdc-slider-color-accessible(error, $mat-theme-styles-query);
// TODO: disabled until we implement the new MDC slider.
// @include mdc-slider-color-accessible(error, $mat-theme-styles-query);
}
}
}
Expand All @@ -21,7 +25,8 @@
@mixin mat-mdc-slider-typography($config-or-theme) {
$config: mat-get-typography-config($config-or-theme);
@include mat-using-mdc-typography($config) {
@include mdc-slider-core-styles($query: $mat-typography-styles-query);
// TODO: disabled until we implement the new MDC slider.
// @include mdc-slider-core-styles($query: $mat-typography-styles-query);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/material-experimental/mdc-slider/slider.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {browser, by, element} from 'protractor';

describe('mat-slider', () => {
// TODO: disabled until we implement the new MDC slider.
describe('mat-slider dummy' , () => it('', () => {}));

// tslint:disable-next-line:ban
xdescribe('mat-slider', () => {
beforeEach(async () => await browser.get('/mdc-slider'));

it('should show a slider', async () => {
Expand Down
14 changes: 1 addition & 13 deletions src/material-experimental/mdc-slider/slider.html
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
<div class="mdc-slider__track-container">
<div class="mdc-slider__track" #track></div>
<div class="mdc-slider__track-marker-container" #trackMarker></div>
</div>
<div class="mdc-slider__thumb-container" #thumbContainer>
<div *ngIf="thumbLabel" class="mdc-slider__pin">
<span class="mdc-slider__pin-value-marker">{{displayValue}}</span>
</div>
<svg class="mdc-slider__thumb" focusable="false" width="21" height="21">
<circle cx="10.5" cy="10.5" r="7.875"></circle>
</svg>
<div class="mdc-slider__focus-ring"></div>
</div>
<!-- TODO: to be implemented as a part of the new MDC slider -->
9 changes: 6 additions & 3 deletions src/material-experimental/mdc-slider/slider.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@import '@material/slider/mixins.import';
// TODO: disabled until we implement the new MDC slider.
// @import '@material/slider/mixins.import';
@import '../mdc-helpers/mdc-helpers';
@import '../../cdk/a11y/a11y';

$mat-slider-min-size: 128px !default;
$mat-slider-horizontal-margin: 8px !default;

@include mdc-slider-core-styles($query: $mat-base-styles-without-animation-query);
// TODO: disabled until we implement the new MDC slider.
// @include mdc-slider-core-styles($query: $mat-base-styles-without-animation-query);

// Overwrites the mdc-slider default styles to match the visual appearance of the
// Angular Material standard slider. This involves making the slider an inline-block
Expand Down Expand Up @@ -45,7 +47,8 @@ $mat-slider-horizontal-margin: 8px !default;
// In order to make it possible for developers to disable animations for a slider,
// we only activate the MDC slider animation styles if animations are enabled.
.mat-mdc-slider:not(._mat-animation-noopable) {
@include mdc-slider-core-styles($query: animation);
// TODO: disabled until we implement the new MDC slider.
// @include mdc-slider-core-styles($query: animation);
}

// Sliders without a thumb label (aka non-discrete) currently cannot have ticks
Expand Down
6 changes: 5 additions & 1 deletion src/material-experimental/mdc-slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {MatSlider, MatSliderModule} from './index';

describe('MDC-based MatSlider', () => {
// TODO: disabled until we implement the new MDC slider.
describe('MDC-based MatSlider dummy' , () => it('', () => {}));

// tslint:disable-next-line:ban
xdescribe('MDC-based MatSlider', () => {
function createComponent<T>(component: Type<T>): ComponentFixture<T> {
TestBed.configureTestingModule({
imports: [
Expand Down
143 changes: 52 additions & 91 deletions src/material-experimental/mdc-slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
AfterViewInit,
Attribute,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Expand All @@ -37,7 +36,7 @@ import {
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
import {ThemePalette} from '@angular/material/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
import {MDCSliderAdapter, MDCSliderFoundation} from '@material/slider';
import {MDCSliderAdapter, MDCSliderFoundation, Thumb} from '@material/slider';
import {Subscription} from 'rxjs';

/**
Expand All @@ -53,10 +52,14 @@ const MIN_AUTO_TICK_SEPARATION = 30;
*/
const TICK_MARKER_SIZE = 2;

// TODO: disabled until we implement the new MDC slider.
/** Event options used to bind passive listeners. */
// tslint:disable-next-line:no-unused-variable
const passiveListenerOptions = normalizePassiveListenerOptions({passive: true});

// TODO: disabled until we implement the new MDC slider.
/** Event options used to bind active listeners. */
// tslint:disable-next-line:no-unused-variable
const activeListenerOptions = normalizePassiveListenerOptions({passive: false});

/**
Expand Down Expand Up @@ -222,87 +225,35 @@ export class MatSlider implements AfterViewInit, OnChanges, OnDestroy, ControlVa

/** Adapter for the MDC slider foundation. */
private _sliderAdapter: MDCSliderAdapter = {
hasClass: (className) => this._elementRef.nativeElement.classList.contains(className),
addClass: (className) => this._elementRef.nativeElement.classList.add(className),
removeClass: (className) => this._elementRef.nativeElement.classList.remove(className),
getAttribute: (name) => this._elementRef.nativeElement.getAttribute(name),
setAttribute: (name, value) => this._elementRef.nativeElement.setAttribute(name, value),
removeAttribute: (name) => this._elementRef.nativeElement.removeAttribute(name),
computeBoundingRect: () => this._elementRef.nativeElement.getBoundingClientRect(),
getTabIndex: () => this._elementRef.nativeElement.tabIndex,
registerInteractionHandler: (evtType, handler) =>
// Interaction event handlers (which handle keyboard interaction) cannot be passive
// as they will prevent the default behavior. Additionally we can't run these event
// handlers outside of the Angular zone because we rely on the events to cause the
// component tree to be re-checked.
// TODO: take in the event listener options from the adapter once MDC supports it.
this._elementRef.nativeElement.addEventListener(evtType, handler, activeListenerOptions),
deregisterInteractionHandler: (evtType, handler) =>
this._elementRef.nativeElement.removeEventListener(evtType, handler),
registerThumbContainerInteractionHandler: (evtType, handler) => {
// The thumb container interaction handlers are currently just used for transition
// events which don't need to run in the Angular zone.
this._ngZone.runOutsideAngular(() => {
this._thumbContainer.nativeElement
.addEventListener(evtType, handler, passiveListenerOptions);
});
},
deregisterThumbContainerInteractionHandler: (evtType, handler) => {
this._thumbContainer.nativeElement
.removeEventListener(evtType, handler, passiveListenerOptions);
},
registerBodyInteractionHandler: (evtType, handler) =>
// Body event handlers (which handle thumb sliding) cannot be passive as they will
// prevent the default behavior. Additionally we can't run these event handlers
// outside of the Angular zone because we rely on the events to cause the component
// tree to be re-checked.
document.body.addEventListener(evtType, handler),
deregisterBodyInteractionHandler: (evtType, handler) =>
document.body.removeEventListener(evtType, handler),
registerResizeHandler: (handler) => {
// The resize handler is currently responsible for detecting slider dimension
// changes and therefore doesn't cause a value change that needs to be propagated.
this._ngZone.runOutsideAngular(() => window.addEventListener('resize', handler));
},
deregisterResizeHandler: (handler) => window.removeEventListener('resize', handler),
notifyInput:
() => {
const newValue = this._foundation.getValue();
// MDC currently fires the input event multiple times.
// TODO(devversion): remove this check once the input notifications are fixed.
if (newValue !== this.value) {
this.value = newValue;
this.input.emit(this._createChangeEvent(newValue));
}
},
notifyChange:
() => {
// TODO(devversion): bug in MDC where only the "change" event is emitted if a keypress
// updated the value. Material and native range sliders also emit an input event.
// Usually we sync the "value" in the "input" event, but as a workaround we now sync
// the value in the "change" event.
this.value = this._foundation.getValue();
this._emitChangeEvent(this.value!);
},
setThumbContainerStyleProperty:
(propertyName, value) => {
this._thumbContainer.nativeElement.style.setProperty(propertyName, value);
},
setTrackStyleProperty:
(propertyName, value) => {
this._track.nativeElement.style.setProperty(propertyName, value);
},
setMarkerValue:
() => {
// Mark the component for check as the thumb label needs to be re-rendered.
this._changeDetectorRef.markForCheck();
},
setTrackMarkers:
(step, max, min) => {
this._trackMarker.nativeElement.style.setProperty(
'background', this._getTrackMarkersBackground(min, max, step));
},
isRTL: () => this._isRtl(),
hasClass: (_className: string) => false,
addClass: (_className: string) => {},
removeClass: (_className: string) => {},
getAttribute: (_attribute: string) => null,
addThumbClass: (_className: string, _thumb: Thumb) => {},
removeThumbClass: (_className: string, _thumb: Thumb) => {},
getThumbAttribute: (_attribute: string, _thumb: Thumb) => null,
setThumbAttribute: (_attribute: string, _value: string, _thumb: Thumb) => {},
getThumbKnobWidth: (_thumb: Thumb) => 0,
isThumbFocused: (_thumb: Thumb) => false,
focusThumb: (_thumb: Thumb) => {},
getThumbBoundingClientRect: (_thumb: Thumb) => null!,
getBoundingClientRect: () => null!,
isRTL: () => false,
setThumbStyleProperty: (_propertyName: string, _value: string, _thumb: Thumb) => {},
setTrackActiveStyleProperty: (_propertyName: string, _value: string) => {},
setValueIndicatorText: (_value: number, _thumb: Thumb) => {},
updateTickMarks: () => {},
setPointerCapture: (_pointerId: number) => {},
emitChangeEvent: (_value: number, _thumb: Thumb) => {},
emitInputEvent: (_value: number, _thumb: Thumb) => {},
registerEventHandler: () => {},
deregisterEventHandler: () => {},
registerThumbEventHandler: () => {},
deregisterThumbEventHandler: () => {},
registerBodyEventHandler: () => {},
deregisterBodyEventHandler: () => {},
registerWindowEventHandler: () => {},
deregisterWindowEventHandler: () => {},
};

/** Instance of the MDC slider foundation for this slider. */
Expand All @@ -327,7 +278,6 @@ export class MatSlider implements AfterViewInit, OnChanges, OnDestroy, ControlVa

constructor(
private _elementRef: ElementRef<HTMLElement>,
private _changeDetectorRef: ChangeDetectorRef,
private _ngZone: NgZone,
private _platform: Platform,
@Optional() private _dir: Directionality,
Expand All @@ -354,7 +304,7 @@ export class MatSlider implements AfterViewInit, OnChanges, OnDestroy, ControlVa
// The MDC slider foundation accesses DOM globals, so we cannot initialize the
// foundation on the server. The foundation would be needed to move the thumb
// to the proper position and to render the ticks.
this._foundation.init();
// this._foundation.init();

// The standard Angular Material slider is always using discrete values. We always
// want to enable discrete values and support ticks, but want to still provide
Expand Down Expand Up @@ -437,14 +387,18 @@ export class MatSlider implements AfterViewInit, OnChanges, OnDestroy, ControlVa
return event;
}

// TODO: disabled until we implement the new MDC slider.
/** Emits a change event and notifies the control value accessor. */
// tslint:disable-next-line:no-unused-variable
private _emitChangeEvent(newValue: number) {
this._controlValueAccessorChangeFn(newValue);
this.valueChange.emit(newValue);
this.change.emit(this._createChangeEvent(newValue));
}

// TODO: disabled until we implement the new MDC slider.
/** Computes the CSS background value for the track markers (aka ticks). */
// tslint:disable-next-line:no-unused-variable
private _getTrackMarkersBackground(min: number, max: number, step: number) {
if (!this.tickInterval) {
return '';
Expand Down Expand Up @@ -476,32 +430,39 @@ export class MatSlider implements AfterViewInit, OnChanges, OnDestroy, ControlVa
// the markers dynamically. This is a workaround until we can get a public API for it. See:
// https://github.com/material-components/material-components-web/issues/5020
(this._foundation as any).hasTrackMarker_ = this.tickInterval !== 0;
this._foundation.setupTrackMarker();

// TODO: disabled until we implement the new MDC slider.
// this._foundation.setupTrackMarker();
}

/** Syncs the "step" input value with the MDC foundation. */
private _syncStep() {
this._foundation.setStep(this.step);
// TODO: disabled until we implement the new MDC slider.
// this._foundation.setStep(this.step);
}

/** Syncs the "max" input value with the MDC foundation. */
private _syncMax() {
this._foundation.setMax(this.max);
// TODO: disabled until we implement the new MDC slider.
// this._foundation.setMax(this.max);
}

/** Syncs the "min" input value with the MDC foundation. */
private _syncMin() {
this._foundation.setMin(this.min);
// TODO: disabled until we implement the new MDC slider.
// this._foundation.setMin(this.min);
}

/** Syncs the "value" input binding with the MDC foundation. */
private _syncValue() {
this._foundation.setValue(this.value!);
// TODO: disabled until we implement the new MDC slider.
// this._foundation.setValue(this.value!);
}

/** Syncs the "disabled" input value with the MDC foundation. */
private _syncDisabled() {
this._foundation.setDisabled(this.disabled);
// TODO: disabled until we implement the new MDC slider.
// this._foundation.setDisabled(this.disabled);
}

/** Whether the slider is displayed in RTL-mode. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import {runHarnessTests} from '@angular/material/slider/testing/shared.spec';
import {MatSliderModule} from '../index';
import {MatSliderHarness} from './slider-harness';

describe('MDC-based MatSliderHarness', () => {
// TODO: disabled until we implement the new MDC slider.
describe('MDC-based MatSliderHarness dummy' , () => it('', () => {}));

// tslint:disable-next-line:ban
xdescribe('MDC-based MatSliderHarness', () => {
runHarnessTests(MatSliderModule, MatSliderHarness as any, {
supportsVertical: false,
supportsInvert: false,
Expand Down
Loading