88
99import { ALT , CONTROL , MAC_META , META , SHIFT } from '@angular/cdk/keycodes' ;
1010import { Inject , Injectable , InjectionToken , OnDestroy , Optional , NgZone } from '@angular/core' ;
11- import { normalizePassiveListenerOptions , Platform } from '@angular/cdk/platform' ;
11+ import { normalizePassiveListenerOptions , Platform , _getEventTarget } from '@angular/cdk/platform' ;
1212import { DOCUMENT } from '@angular/common' ;
1313import { BehaviorSubject , Observable } from 'rxjs' ;
1414import { distinctUntilChanged , skip } from 'rxjs/operators' ;
@@ -128,7 +128,7 @@ export class InputModalityDetector implements OnDestroy {
128128 if ( this . _options ?. ignoreKeys ?. some ( keyCode => keyCode === event . keyCode ) ) { return ; }
129129
130130 this . _modality . next ( 'keyboard' ) ;
131- this . _mostRecentTarget = getTarget ( event ) ;
131+ this . _mostRecentTarget = _getEventTarget ( event ) ;
132132 }
133133
134134 /**
@@ -144,7 +144,7 @@ export class InputModalityDetector implements OnDestroy {
144144 // Fake mousedown events are fired by some screen readers when controls are activated by the
145145 // screen reader. Attribute them to keyboard input modality.
146146 this . _modality . next ( isFakeMousedownFromScreenReader ( event ) ? 'keyboard' : 'mouse' ) ;
147- this . _mostRecentTarget = getTarget ( event ) ;
147+ this . _mostRecentTarget = _getEventTarget ( event ) ;
148148 }
149149
150150 /**
@@ -164,7 +164,7 @@ export class InputModalityDetector implements OnDestroy {
164164 this . _lastTouchMs = Date . now ( ) ;
165165
166166 this . _modality . next ( 'touch' ) ;
167- this . _mostRecentTarget = getTarget ( event ) ;
167+ this . _mostRecentTarget = _getEventTarget ( event ) ;
168168 }
169169
170170 constructor (
@@ -203,10 +203,3 @@ export class InputModalityDetector implements OnDestroy {
203203 document . removeEventListener ( 'touchstart' , this . _onTouchstart , modalityEventListenerOptions ) ;
204204 }
205205}
206-
207- /** Gets the target of an event, accounting for Shadow DOM. */
208- export function getTarget ( event : Event ) : HTMLElement | null {
209- // If an event is bound outside the Shadow DOM, the `event.target` will
210- // point to the shadow root so we have to use `composedPath` instead.
211- return ( event . composedPath ? event . composedPath ( ) [ 0 ] : event . target ) as HTMLElement | null ;
212- }
0 commit comments