@@ -8,26 +8,104 @@ export class IgxTextSelectionDirective {
8
8
9
9
private selectionState = true ;
10
10
11
+ /**
12
+ * Returns whether the input element is selectable through the directive.
13
+ *
14
+ * ```typescript
15
+ * // get
16
+ * @ViewChild ('firstName',
17
+ * {read: IgxTextSelectionDirective})
18
+ * public firstName: IgxTextSelectionDirective;
19
+ *
20
+ * public getFirstNameSelectionStatus() {
21
+ * return this.firstName.selected;
22
+ * }
23
+ * ```
24
+ */
11
25
@Input ( 'igxTextSelection' )
12
26
get selected ( ) : boolean {
13
27
return this . selectionState ;
14
28
}
15
29
30
+ /**
31
+ * Determines whether the input element could be selected through the directive.
32
+ *
33
+ *```html
34
+ * <!--set-->
35
+ * <input
36
+ * type="text"
37
+ * id="firstName"
38
+ * [igxTextSelection]="true">
39
+ * </input>
40
+ *
41
+ * <input
42
+ * type="text"
43
+ * id="lastName"
44
+ * igxTextSelection
45
+ * [selected]="true">
46
+ * </input>
47
+ * ```
48
+ */
16
49
set selected ( val : boolean ) {
17
50
this . selectionState = val ;
18
51
}
19
52
53
+ /**
54
+ * Returns the nativeElement of the element where the directive was applied.
55
+ *
56
+ * ```html
57
+ * <input
58
+ * type="text"
59
+ * id="firstName"
60
+ * igxTextSelection>
61
+ * </input>
62
+ * ```
63
+ *
64
+ * ```typescript
65
+ * @ViewChild ('firstName',
66
+ * {read: IgxTextSelectionDirective})
67
+ * public inputElement: IgxTextSelectionDirective;
68
+ *
69
+ * public getNativeElement() {
70
+ * return this.inputElement.nativeElement;
71
+ * }
72
+ * ```
73
+ */
20
74
get nativeElement ( ) {
21
75
return this . element . nativeElement ;
22
76
}
23
77
78
+ /**
79
+ * @hidden
80
+ */
24
81
@HostListener ( 'focus' )
25
82
onFocus ( ) {
26
83
this . trigger ( ) ;
27
84
}
28
85
29
86
constructor ( private element : ElementRef ) { }
30
87
88
+ /**
89
+ * Triggers the selection of the element if it is marked as selectable.
90
+ *
91
+ * ```html
92
+ * <input
93
+ * type="text"
94
+ * id="firstName"
95
+ * igxTextSelection>
96
+ * </input>
97
+ * ```
98
+ *
99
+ * ```typescript
100
+ * @ViewChild ('firstName',
101
+ * {read: IgxTextSelectionDirective})
102
+ * public inputElement: IgxTextSelectionDirective;
103
+ *
104
+ * public triggerElementSelection() {
105
+ * this.inputElement.trigger();
106
+ * }
107
+ * ```
108
+ */
31
109
trigger ( ) {
32
110
if ( this . selected && this . nativeElement . value . length ) {
33
111
requestAnimationFrame ( ( ) => this . nativeElement . setSelectionRange ( 0 , this . nativeElement . value . length ) ) ;
0 commit comments