Skip to content

fix(multiple): remove backwards-compatibility code #30747

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 31, 2025
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
14 changes: 0 additions & 14 deletions goldens/cdk/platform/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
```ts

import * as i0 from '@angular/core';
import { Renderer2 } from '@angular/core';

// @public
export function _bindEventWithOptions(renderer: Renderer2, target: EventTarget, eventName: string, callback: (event: any) => boolean | void, options: _ListenerOptions): () => void;

// @public
export function _getEventTarget<T extends EventTarget>(event: Event): T | null;
Expand All @@ -28,16 +24,6 @@ export function getSupportedInputTypes(): Set<string>;
// @public
export function _isTestEnvironment(): boolean;

// @public
export interface _ListenerOptions {
// (undocumented)
capture?: boolean;
// (undocumented)
once?: boolean;
// (undocumented)
passive?: boolean;
}

// @public
export function normalizePassiveListenerOptions(options: AddEventListenerOptions): AddEventListenerOptions | boolean;

Expand Down
5 changes: 1 addition & 4 deletions src/cdk-experimental/popover-edit/table-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
withLatestFrom,
} from 'rxjs/operators';

import {_bindEventWithOptions} from '@angular/cdk/platform';
import {CELL_SELECTOR, EDIT_PANE_CLASS, EDIT_PANE_SELECTOR, ROW_SELECTOR} from './constants';
import {EditEventDispatcher, HoverContentState} from './edit-event-dispatcher';
import {EditRef} from './edit-ref';
Expand Down Expand Up @@ -136,9 +135,7 @@ export class CdkEditable implements AfterViewInit, OnDestroy {
) {
return new Observable<T>(subscriber => {
const handler = (event: T) => subscriber.next(event);
const cleanup = options
? _bindEventWithOptions(this._renderer, element, name, handler, options)
: this._renderer.listen(element, name, handler, options);
const cleanup = this._renderer.listen(element, name, handler, options);
return () => {
cleanup();
subscriber.complete();
Expand Down
26 changes: 4 additions & 22 deletions src/cdk/a11y/input-modality/input-modality-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
inject,
RendererFactory2,
} from '@angular/core';
import {Platform, _bindEventWithOptions, _getEventTarget} from '../../platform';
import {Platform, _getEventTarget} from '../../platform';
import {DOCUMENT} from '@angular/common';
import {BehaviorSubject, Observable} from 'rxjs';
import {distinctUntilChanged, skip} from 'rxjs/operators';
Expand Down Expand Up @@ -205,27 +205,9 @@ export class InputModalityDetector implements OnDestroy {

this._listenerCleanups = ngZone.runOutsideAngular(() => {
return [
_bindEventWithOptions(
renderer,
document,
'keydown',
this._onKeydown,
modalityEventListenerOptions,
),
_bindEventWithOptions(
renderer,
document,
'mousedown',
this._onMousedown,
modalityEventListenerOptions,
),
_bindEventWithOptions(
renderer,
document,
'touchstart',
this._onTouchstart,
modalityEventListenerOptions,
),
renderer.listen(document, 'keydown', this._onKeydown, modalityEventListenerOptions),
renderer.listen(document, 'mousedown', this._onMousedown, modalityEventListenerOptions),
renderer.listen(document, 'touchstart', this._onTouchstart, modalityEventListenerOptions),
];
});
}
Expand Down
12 changes: 5 additions & 7 deletions src/cdk/drag-drop/drag-drop-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ChangeDetectionStrategy,
Component,
Injectable,
ListenerOptions,
NgZone,
OnDestroy,
RendererFactory2,
Expand All @@ -19,7 +20,6 @@ import {
signal,
} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {_bindEventWithOptions, _ListenerOptions} from '../platform';
import {_CdkPrivateStyleLoader} from '../private';
import {Observable, Observer, Subject, merge} from 'rxjs';
import type {DropListRef} from './drop-list-ref';
Expand Down Expand Up @@ -123,8 +123,7 @@ export class DragDropRegistry implements OnDestroy {
// The event handler has to be explicitly active,
// because newer browsers make it passive by default.
this._cleanupDocumentTouchmove?.();
this._cleanupDocumentTouchmove = _bindEventWithOptions(
this._renderer,
this._cleanupDocumentTouchmove = this._renderer.listen(
this._document,
'touchmove',
this._persistentTouchmoveListener,
Expand Down Expand Up @@ -170,7 +169,7 @@ export class DragDropRegistry implements OnDestroy {
const isTouchEvent = event.type.startsWith('touch');
const endEventHandler = (e: Event) => this.pointerUp.next(e as TouchEvent | MouseEvent);

const toBind: [name: string, handler: (event: Event) => void, options: _ListenerOptions][] = [
const toBind: [name: string, handler: (event: Event) => void, options: ListenerOptions][] = [
// Use capturing so that we pick up scroll changes in any scrollable nodes that aren't
// the document. See https://github.com/angular/components/issues/17144.
['scroll', (e: Event) => this._scroll.next(e), capturingEventOptions],
Expand Down Expand Up @@ -203,7 +202,7 @@ export class DragDropRegistry implements OnDestroy {

this._ngZone.runOutsideAngular(() => {
this._globalListeners = toBind.map(([name, handler, options]) =>
_bindEventWithOptions(this._renderer, this._document, name, handler, options),
this._renderer.listen(this._document, name, handler, options),
);
});
}
Expand Down Expand Up @@ -247,8 +246,7 @@ export class DragDropRegistry implements OnDestroy {
streams.push(
new Observable((observer: Observer<Event>) => {
return this._ngZone.runOutsideAngular(() => {
const cleanup = _bindEventWithOptions(
this._renderer,
const cleanup = this._renderer.listen(
shadowRoot as ShadowRoot,
'scroll',
(event: Event) => {
Expand Down
30 changes: 6 additions & 24 deletions src/cdk/drag-drop/drag-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {isFakeMousedownFromScreenReader, isFakeTouchstartFromScreenReader} from '../a11y';
import {Direction} from '../bidi';
import {coerceElement} from '../coercion';
import {_getEventTarget, _getShadowRoot, _bindEventWithOptions} from '../platform';
import {_getEventTarget, _getShadowRoot} from '../platform';
import {ViewportRuler} from '../scrolling';
import {
ElementRef,
Expand Down Expand Up @@ -457,28 +457,11 @@ export class DragRef<T = any> {

if (element !== this._rootElement) {
this._removeRootElementListeners();
const renderer = this._renderer;
this._rootElementCleanups = this._ngZone.runOutsideAngular(() => [
_bindEventWithOptions(
this._renderer,
element,
'mousedown',
this._pointerDown,
activeEventListenerOptions,
),
_bindEventWithOptions(
this._renderer,
element,
'touchstart',
this._pointerDown,
passiveEventListenerOptions,
),
_bindEventWithOptions(
this._renderer,
element,
'dragstart',
this._nativeDragStart,
activeEventListenerOptions,
),
renderer.listen(element, 'mousedown', this._pointerDown, activeEventListenerOptions),
renderer.listen(element, 'touchstart', this._pointerDown, passiveEventListenerOptions),
renderer.listen(element, 'dragstart', this._nativeDragStart, activeEventListenerOptions),
]);
this._initialTransform = undefined;
this._rootElement = element;
Expand Down Expand Up @@ -832,8 +815,7 @@ export class DragRef<T = any> {
// In some browsers the global `selectstart` that we maintain in the `DragDropRegistry`
// doesn't cross the shadow boundary so we have to prevent it at the shadow root (see #28792).
this._ngZone.runOutsideAngular(() => {
this._cleanupShadowRootSelectStart = _bindEventWithOptions(
this._renderer,
this._cleanupShadowRootSelectStart = this._renderer.listen(
shadowRoot,
'selectstart',
shadowDomSelectStart,
Expand Down
23 changes: 6 additions & 17 deletions src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {Injectable, NgZone, RendererFactory2, inject} from '@angular/core';
import {Platform, _bindEventWithOptions, _getEventTarget} from '../../platform';
import {Platform, _getEventTarget} from '../../platform';
import {BaseOverlayDispatcher} from './base-overlay-dispatcher';
import type {OverlayRef} from '../overlay-ref';

Expand Down Expand Up @@ -40,24 +40,13 @@ export class OverlayOutsideClickDispatcher extends BaseOverlayDispatcher {
if (!this._isAttached) {
const body = this._document.body;
const eventOptions = {capture: true};
const renderer = this._renderer;

this._cleanups = this._ngZone.runOutsideAngular(() => [
_bindEventWithOptions(
this._renderer,
body,
'pointerdown',
this._pointerDownListener,
eventOptions,
),
_bindEventWithOptions(this._renderer, body, 'click', this._clickListener, eventOptions),
_bindEventWithOptions(this._renderer, body, 'auxclick', this._clickListener, eventOptions),
_bindEventWithOptions(
this._renderer,
body,
'contextmenu',
this._clickListener,
eventOptions,
),
renderer.listen(body, 'pointerdown', this._pointerDownListener, eventOptions),
renderer.listen(body, 'click', this._clickListener, eventOptions),
renderer.listen(body, 'auxclick', this._clickListener, eventOptions),
renderer.listen(body, 'contextmenu', this._clickListener, eventOptions),
]);

// click event is not fired on iOS. To make element "clickable" we are
Expand Down
47 changes: 0 additions & 47 deletions src/cdk/platform/features/backwards-compatibility.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/cdk/platform/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ export * from './features/passive-listeners';
export * from './features/scrolling';
export * from './features/shadow-dom';
export * from './features/test-environment';
export * from './features/backwards-compatibility';
10 changes: 2 additions & 8 deletions src/cdk/text-field/autofill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import {Platform, _bindEventWithOptions} from '../platform';
import {Platform} from '../platform';
import {
Directive,
ElementRef,
Expand Down Expand Up @@ -111,13 +111,7 @@ export class AutofillMonitor implements OnDestroy {

const unlisten = this._ngZone.runOutsideAngular(() => {
element.classList.add('cdk-text-field-autofill-monitored');
return _bindEventWithOptions(
this._renderer,
element,
'animationstart',
listener,
listenerOptions,
);
return this._renderer.listen(element, 'animationstart', listener, listenerOptions);
});

this._monitoredElements.set(element, {subject, unlisten});
Expand Down
18 changes: 6 additions & 12 deletions src/material/core/private/ripple-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
RippleTarget,
defaultRippleAnimationConfig,
} from '../ripple';
import {Platform, _bindEventWithOptions, _getEventTarget} from '@angular/cdk/platform';
import {Platform, _getEventTarget} from '@angular/cdk/platform';
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';
import {_animationsDisabled} from '../animation/animation';

Expand Down Expand Up @@ -65,17 +65,11 @@ export class MatRippleLoader implements OnDestroy {
constructor() {
const renderer = inject(RendererFactory2).createRenderer(null, null);

this._eventCleanups = this._ngZone.runOutsideAngular(() => {
return rippleInteractionEvents.map(name =>
_bindEventWithOptions(
renderer,
this._document,
name,
this._onInteraction,
eventListenerOptions,
),
);
});
this._eventCleanups = this._ngZone.runOutsideAngular(() =>
rippleInteractionEvents.map(name =>
renderer.listen(this._document, name, this._onInteraction, eventListenerOptions),
),
);
}

ngOnDestroy(): void {
Expand Down
Loading
Loading