Skip to content

fix(material-experimental/mdc-slider): resolve warnings about active event listeners #18583

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
Mar 9, 2020
Merged
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
52 changes: 26 additions & 26 deletions src/material-experimental/mdc-slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ const MIN_AUTO_TICK_SEPARATION = 30;
*/
const TICK_MARKER_SIZE = 2;

/** Options to pass to the slider interaction listeners. */
const listenerOptions = normalizePassiveListenerOptions({passive: true});
/** Event options used to bind passive listeners. */
const passiveListenerOptions = normalizePassiveListenerOptions({passive: true});

/** Event options used to bind active listeners. */
const activeListenerOptions = normalizePassiveListenerOptions({passive: false});

/**
* Provider Expression that allows mat-slider to register as a ControlValueAccessor.
Expand Down Expand Up @@ -232,39 +235,36 @@ export class MatSlider implements AfterViewInit, OnChanges, OnDestroy, ControlVa
// 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.
this._elementRef.nativeElement.addEventListener(evtType, handler),
// 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, listenerOptions);
});
},
deregisterThumbContainerInteractionHandler:
(evtType, handler) => {
this._thumbContainer.nativeElement.removeEventListener(evtType, handler, listenerOptions);
},
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),
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, listenerOptions);
});
},
deregisterResizeHandler: (handler) =>
window.removeEventListener('resize', handler, listenerOptions),
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();
Expand Down