• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / ac83a13a-8fb5-40cb-ba8d-44387842a204

pending completion
ac83a13a-8fb5-40cb-ba8d-44387842a204

push

circleci

minlovehua
feat(input): support input count for textarea #INFR-9159

5104 of 6317 branches covered (80.8%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

12904 of 13657 relevant lines covered (94.49%)

974.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.47
/src/input/input-group.component.ts
1
import {
2
    Component,
3
    HostBinding,
4
    Input,
5
    ContentChild,
6
    TemplateRef,
7
    ViewEncapsulation,
8
    ChangeDetectionStrategy,
9
    AfterContentChecked,
10
    OnInit,
1✔
11
    ElementRef,
12
    OnDestroy
13
} from '@angular/core';
14
import { MixinBase, ThyTranslate, mixinUnsubscribe } from 'ngx-tethys/core';
15
import { useHostRenderer } from '@tethys/cdk/dom';
16
import { ThyInputDirective } from './input.directive';
17
import { NgIf, NgTemplateOutlet } from '@angular/common';
18
import { FocusMonitor } from '@angular/cdk/a11y';
19
import { takeUntil } from 'rxjs/operators';
20

1✔
21
export type InputGroupSize = 'sm' | 'lg' | 'md' | '';
22

8✔
23
const inputGroupSizeMap = {
24
    sm: ['input-group-sm'],
25
    lg: ['input-group-lg'],
8!
26
    md: ['input-group-md']
8✔
27
};
28

29
/**
30
 * 输入框分组
8✔
31
 * @name thy-input-group
32
 * @order 20
33
 */
8!
34
@Component({
8✔
35
    selector: 'thy-input-group',
36
    templateUrl: './input-group.component.html',
37
    changeDetection: ChangeDetectionStrategy.OnPush,
38
    encapsulation: ViewEncapsulation.None,
18✔
39
    host: {
3✔
40
        class: 'thy-input-group',
41
        '[class.form-control]': 'prefixTemplate || suffixTemplate',
42
        '[class.thy-input-group-with-prefix]': 'prefixTemplate',
15✔
43
        '[class.thy-input-group-with-suffix]': 'suffixTemplate',
44
        '[class.thy-input-group-with-textarea-suffix]': 'isTextareaSuffix'
45
    },
46
    standalone: true,
28✔
47
    imports: [NgIf, NgTemplateOutlet]
28✔
48
})
28✔
49
export class ThyInputGroupComponent extends mixinUnsubscribe(MixinBase) implements OnInit, AfterContentChecked, OnDestroy {
28✔
50
    private hostRenderer = useHostRenderer();
28✔
51

28✔
52
    public appendText: string;
53

54
    public prependText: string;
28✔
55

56
    public isTextareaSuffix: boolean;
57

58
    @HostBinding('class.disabled') disabled = false;
2!
59

2✔
60
    /**
61
     * 输入框上添加的后置文本
62
     */
×
63
    @Input()
64
    set thyAppendText(value: string) {
65
        this.appendText = value;
66
    }
67

43✔
68
    /**
43✔
69
     * 输入框上添加的后置文本多语言 Key
70
     */
71
    @Input()
28✔
72
    set thyAppendTextTranslateKey(value: string) {
28✔
73
        if (value) {
74
            this.appendText = this.thyTranslate.instant(value);
1✔
75
        }
76
    }
77

78
    /**
79
     * 输入框上添加的前置文本
1✔
80
     */
81
    @Input()
82
    set thyPrependText(value: string) {
83
        this.prependText = value;
84
    }
85

86
    /**
87
     * 输入框上添加的前置文本多语言 Key
88
     */
89
    @Input()
90
    set thyPrependTextTranslateKey(value: string) {
91
        if (value) {
92
            this.prependText = this.thyTranslate.instant(value);
93
        }
1✔
94
    }
95

96
    /**
97
     * 输入框分组大小
98
     * @type 'sm' | 'lg' | 'md' | ''
99
     * @default ''
100
     */
101
    @Input()
102
    set thySize(size: InputGroupSize) {
103
        if (size && inputGroupSizeMap[size]) {
104
            this.hostRenderer.updateClass(inputGroupSizeMap[size]);
105
        } else {
106
            this.hostRenderer.updateClass([]);
107
        }
108
    }
109

110
    /**
111
     * 后置模板
112
     */
113
    @ContentChild('append') appendTemplate: TemplateRef<unknown>;
114

115
    /**
116
     * 前置模板
117
     */
118
    @ContentChild('prepend') prependTemplate: TemplateRef<unknown>;
119

120
    /**
121
     * 前缀
122
     */
123
    @ContentChild('prefix') prefixTemplate: TemplateRef<unknown>;
124

125
    /**
126
     * 后缀
127
     */
128
    @ContentChild('suffix') suffixTemplate: TemplateRef<unknown>;
129

130
    /**
131
     * @private
132
     */
133
    @ContentChild(ThyInputDirective) inputDirective: ThyInputDirective;
134

135
    constructor(private thyTranslate: ThyTranslate, private elementRef: ElementRef, private focusMonitor: FocusMonitor) {
136
        super();
137
    }
138

139
    ngOnInit() {
140
        this.focusMonitor
141
            .monitor(this.elementRef.nativeElement, true)
142
            .pipe(takeUntil(this.ngUnsubscribe$))
143
            .subscribe(origin => {
144
                if (origin) {
145
                    this.hostRenderer.addClass('form-control-active');
146
                } else {
147
                    this.hostRenderer.removeClass('form-control-active');
148
                }
149
            });
150
    }
151

152
    ngAfterContentChecked(): void {
153
        this.disabled = !!this.inputDirective?.nativeElement?.hasAttribute('disabled');
154
        this.isTextareaSuffix = this.inputDirective?.nativeElement?.tagName === 'TEXTAREA';
155
    }
156

157
    ngOnDestroy() {
158
        super.ngOnDestroy();
159
        this.focusMonitor.stopMonitoring(this.elementRef.nativeElement);
160
    }
161
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc