@@ -51,6 +51,14 @@ export const _MdcTextFieldMixinBase: CanUpdateErrorStateCtor & typeof MdcTextFie
51
51
52
52
let nextUniqueId = 0 ;
53
53
54
+ /**
55
+ * Time in milliseconds for which to ignore mouse events, after
56
+ * receiving a touch event. Used to avoid doing double work for
57
+ * touch devices where the browser fires fake mouse events, in
58
+ * addition to touch events.
59
+ */
60
+ const MOUSE_EVENT_IGNORE_TIME = 800 ;
61
+
54
62
@Component ( {
55
63
moduleId : module . id ,
56
64
selector : 'mdc-text-field' ,
@@ -108,6 +116,9 @@ export class MdcTextField extends _MdcTextFieldMixinBase implements AfterViewIni
108
116
private _uid = `mdc-input-${ nextUniqueId ++ } ` ;
109
117
private _initialized : boolean = false ;
110
118
119
+ /** Time in milliseconds when the last touchstart event happened. */
120
+ private _lastTouchStartEvent : number = 0 ;
121
+
111
122
controlType : string = 'mdc-text-field' ;
112
123
113
124
@Input ( ) label : string | null = null ;
@@ -406,6 +417,17 @@ export class MdcTextField extends _MdcTextFieldMixinBase implements AfterViewIni
406
417
}
407
418
408
419
onInputInteraction ( evt : MouseEvent | TouchEvent ) : void {
420
+ if ( evt instanceof MouseEvent ) {
421
+ const isSyntheticEvent = this . _lastTouchStartEvent &&
422
+ Date . now ( ) < this . _lastTouchStartEvent + MOUSE_EVENT_IGNORE_TIME ;
423
+
424
+ if ( isSyntheticEvent ) {
425
+ return ;
426
+ }
427
+ } else {
428
+ this . _lastTouchStartEvent = Date . now ( ) ;
429
+ }
430
+
409
431
this . _foundation . setTransformOrigin ( evt ) ;
410
432
}
411
433
0 commit comments