7
7
*/
8
8
9
9
import {
10
- AfterContentInit ,
11
10
AfterContentChecked ,
11
+ AfterContentInit ,
12
12
AfterViewInit ,
13
+ ChangeDetectionStrategy ,
13
14
ChangeDetectorRef ,
14
15
Component ,
15
16
ContentChild ,
16
17
ContentChildren ,
17
18
Directive ,
19
+ DoCheck ,
18
20
ElementRef ,
21
+ Inject ,
19
22
Input ,
23
+ OnChanges ,
24
+ OnDestroy ,
20
25
Optional ,
21
26
QueryList ,
22
27
Renderer2 ,
23
28
Self ,
24
29
ViewChild ,
25
30
ViewEncapsulation ,
26
- Inject ,
27
- ChangeDetectionStrategy ,
28
- OnChanges ,
29
- OnDestroy ,
30
- DoCheck ,
31
31
} from '@angular/core' ;
32
32
import { animate , state , style , transition , trigger } from '@angular/animations' ;
33
33
import { coerceBooleanProperty , Platform } from '../core' ;
34
- import { FormGroupDirective , NgControl , NgForm , FormControl } from '@angular/forms' ;
34
+ import { FormControl , FormGroupDirective , NgControl , NgForm } from '@angular/forms' ;
35
35
import { getSupportedInputTypes } from '../core/platform/features' ;
36
36
import {
37
37
getMdInputContainerDuplicatedHintError ,
@@ -41,13 +41,13 @@ import {
41
41
} from './input-container-errors' ;
42
42
import {
43
43
FloatPlaceholderType ,
44
- PlaceholderOptions ,
45
- MD_PLACEHOLDER_GLOBAL_OPTIONS
44
+ MD_PLACEHOLDER_GLOBAL_OPTIONS ,
45
+ PlaceholderOptions
46
46
} from '../core/placeholder/placeholder-options' ;
47
47
import {
48
48
defaultErrorStateMatcher ,
49
- ErrorStateMatcher ,
50
49
ErrorOptions ,
50
+ ErrorStateMatcher ,
51
51
MD_ERROR_GLOBAL_OPTIONS
52
52
} from '../core/error/error-options' ;
53
53
import { Subject } from 'rxjs/Subject' ;
@@ -138,7 +138,6 @@ export class MdSuffix {}
138
138
}
139
139
} )
140
140
export class MdInputDirective implements OnChanges , OnDestroy , DoCheck {
141
-
142
141
/** Variables used as cache for getters and setters. */
143
142
private _type = 'text' ;
144
143
private _placeholder : string = '' ;
@@ -232,7 +231,6 @@ export class MdInputDirective implements OnChanges, OnDestroy, DoCheck {
232
231
constructor ( private _elementRef : ElementRef ,
233
232
private _renderer : Renderer2 ,
234
233
private _platform : Platform ,
235
- private _changeDetectorRef : ChangeDetectorRef ,
236
234
@Optional ( ) @Self ( ) public _ngControl : NgControl ,
237
235
@Optional ( ) private _parentForm : NgForm ,
238
236
@Optional ( ) private _parentFormGroup : FormGroupDirective ,
@@ -242,6 +240,22 @@ export class MdInputDirective implements OnChanges, OnDestroy, DoCheck {
242
240
this . id = this . id ;
243
241
this . _errorOptions = errorOptions ? errorOptions : { } ;
244
242
this . errorStateMatcher = this . _errorOptions . errorStateMatcher || defaultErrorStateMatcher ;
243
+
244
+ // On some versions of iOS the caret gets stuck in the wrong place when holding down the delete
245
+ // key. In order to get around this we need to "jiggle" the caret loose. Since this bug only
246
+ // exists on iOS, we only bother to install the listener on iOS.
247
+ if ( _platform . IOS ) {
248
+ _renderer . listen ( _elementRef . nativeElement , 'keyup' , ( event : Event ) => {
249
+ let el = event . target as HTMLInputElement ;
250
+ if ( ! el . value && ! el . selectionStart && ! el . selectionEnd ) {
251
+ // Note: Just setting `0, 0` doesn't fix the issue. Setting `1, 1` fixes it for the first
252
+ // time that you type text and then hold delete. Toggling to `1, 1` and then back to
253
+ // `0, 0` seems to completely fix it.
254
+ el . setSelectionRange ( 1 , 1 ) ;
255
+ el . setSelectionRange ( 0 , 0 ) ;
256
+ }
257
+ } ) ;
258
+ }
245
259
}
246
260
247
261
ngOnChanges ( ) {
0 commit comments