Skip to content

Commit 8bf832e

Browse files
authored
Merge pull request #2317 from IgniteUI/BPenkov/IgxTextSelectionDirective-docs
Added documentation and code snippets to the IgxTextSelectionDirective
2 parents 7b25e62 + 6ceb68d commit 8bf832e

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

projects/igniteui-angular/src/lib/directives/text-selection/text-selection.directive.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,104 @@ export class IgxTextSelectionDirective {
88

99
private selectionState = true;
1010

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+
*/
1125
@Input('igxTextSelection')
1226
get selected(): boolean {
1327
return this.selectionState;
1428
}
1529

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+
*/
1649
set selected(val: boolean) {
1750
this.selectionState = val;
1851
}
1952

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+
*/
2074
get nativeElement() {
2175
return this.element.nativeElement;
2276
}
2377

78+
/**
79+
* @hidden
80+
*/
2481
@HostListener('focus')
2582
onFocus() {
2683
this.trigger();
2784
}
2885

2986
constructor(private element: ElementRef) { }
3087

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+
*/
31109
trigger() {
32110
if (this.selected && this.nativeElement.value.length) {
33111
requestAnimationFrame(() => this.nativeElement.setSelectionRange(0, this.nativeElement.value.length));

0 commit comments

Comments
 (0)