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

atinc / ngx-tethys / edbc1d43-1648-411a-a6bc-f24c9aa3f654

27 Mar 2025 06:13AM UTC coverage: 90.236% (+0.06%) from 90.179%
edbc1d43-1648-411a-a6bc-f24c9aa3f654

push

circleci

web-flow
Merge pull request #3282 from atinc/v19.0.0-next

5598 of 6865 branches covered (81.54%)

Branch coverage included in aggregate %.

8 of 8 new or added lines in 7 files covered. (100.0%)

157 existing lines in 46 files now uncovered.

13357 of 14141 relevant lines covered (94.46%)

992.51 hits per line

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

93.33
/src/input/input.component.ts
1
import { take } from 'rxjs/operators';
2

3
import { NgTemplateOutlet } from '@angular/common';
4
import {
5
    Component,
6
    ContentChild,
7
    ElementRef,
8
    EventEmitter,
9
    forwardRef,
10
    Input,
11
    NgZone,
1✔
12
    OnInit,
13
    Output,
28✔
14
    TemplateRef,
15
    ViewChild,
16
    ViewEncapsulation,
1✔
17
    inject
1✔
18
} from '@angular/core';
19
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
20
import { ThyIcon } from 'ngx-tethys/icon';
21
import { ThyAutofocusDirective } from 'ngx-tethys/shared';
22
import { ThyInputDirective, ThyInputSize } from './input.directive';
23
import { coerceBooleanProperty } from 'ngx-tethys/util';
1✔
24

25
export const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR: any = {
42✔
26
    provide: NG_VALUE_ACCESSOR,
42✔
27
    useExisting: forwardRef(() => ThyInput),
42✔
28
    multi: true
42✔
29
};
42✔
30

42✔
31
const noop = () => {};
42✔
32

42✔
33
const password = 'password';
42✔
34

42✔
35
/**
42✔
36
 * 内部集成输入框组件,建议 thy-input-group 和 thyInput 组合使用
42✔
37
 * @name thy-input
38
 * @order 50
39
 */
29✔
40
@Component({
41
    selector: 'thy-input',
42
    templateUrl: './input.component.html',
42✔
43
    providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR],
42✔
44
    encapsulation: ViewEncapsulation.None,
14✔
45
    host: {
46
        class: 'thy-input form-control',
47
        '[class.form-control-active]': 'focused',
48
        '[class.disabled]': 'disabled'
49
    },
56✔
50
    imports: [NgTemplateOutlet, ThyInputDirective, ThyAutofocusDirective, FormsModule, ThyIcon]
51
})
52
export class ThyInput implements ControlValueAccessor, OnInit {
28✔
53
    private ngZone = inject(NgZone);
54
    private elementRef = inject(ElementRef);
55

28✔
56
    /**
57
     * Placeholder
58
     */
29✔
59
    @Input() placeholder = '';
60

UNCOV
61
    /**
×
62
     * 输入框大小
63
     * @type 'xs' | 'sm' | 'md' | 'default' | 'lg'
64
     * @default default
3✔
65
     */
3✔
66
    @Input() thySize: ThyInputSize;
3✔
67

68
    /**
69
     * 是否自动聚焦
1✔
70
     */
1!
UNCOV
71
    @Input({ transform: coerceBooleanProperty }) thyAutofocus = false;
×
72

73
    /**
1✔
74
     * 输入框类型
1✔
75
     * @type 'number' | 'input'
1✔
76
     */
77
    @Input()
78
    set thyType(value: string) {
68✔
79
        this.type = value;
80
    }
81

2✔
82
    /**
83
     * @deprecated please use thyType
1✔
84
     */
85
    @Input() type: string;
86

87
    /**
88
     * 输入 Label 文本
89
     */
90
    @Input() thyLabelText: string;
91

92
    /**
93
     * 是否只读
94
     */
95
    @Input({ transform: coerceBooleanProperty }) readonly = false;
96

97
    /**
98
     * focus 聚焦事件
1✔
99
     */
100
    @Output() focus: EventEmitter<Event> = new EventEmitter<Event>();
101

102
    /**
103
     * blur 失焦事件
104
     */
105
    @Output() blur: EventEmitter<Event> = new EventEmitter<Event>();
106

107
    /**
108
     * 后置模板
109
     */
110
    @ContentChild('append') appendTemplate: TemplateRef<any>;
111

112
    /**
113
     * 前置模板
114
     */
115
    @ContentChild('prepend') prependTemplate: TemplateRef<any>;
116

117
    @ViewChild('eye', { static: true }) eyeTemplate: TemplateRef<any>;
118

119
    public _type = 'text';
120

121
    public value: string;
122

123
    public showLabel: boolean;
124

125
    public focused = false;
126

127
    public disabled = false;
128

129
    private onTouchedCallback: () => void = noop;
130

131
    private onChangeCallback: (_: any) => void = noop;
132

133
    ngOnInit() {
134
        this.ngZone.onStable.pipe(take(1)).subscribe(() => {
135
            if (this.isPassword(this.type)) {
136
                this.appendTemplate = this.eyeTemplate;
137
            }
138
        });
139
    }
140

141
    writeValue(value: any): void {
142
        this.value = value;
143
    }
144

145
    registerOnChange(fn: any): void {
146
        this.onChangeCallback = fn;
147
    }
148

149
    registerOnTouched(fn: any): void {
150
        this.onTouchedCallback = fn;
151
    }
152

153
    setDisabledState?(isDisabled: boolean): void {
154
        this.disabled = isDisabled;
155
    }
156

157
    onModelChange() {
158
        this.onChangeCallback(this.value);
159
    }
160

161
    onInputFocus(event: Event) {
162
        this.focused = true;
163
        this.showLabel = true;
164
        this.focus.emit(event);
165
    }
166

167
    onInputBlur(event: Event) {
168
        this.onTouchedCallback();
169
        if (this.elementRef.nativeElement.onblur) {
170
            this.elementRef.nativeElement.onblur(event);
171
        }
172
        this.focused = false;
173
        this.showLabel = false;
174
        this.blur.emit(event);
175
    }
176

177
    isPassword(value: string) {
178
        return value === password;
179
    }
180

181
    togglePasswordType() {
182
        this.type = this.isPassword(this.type) ? 'text' : 'password';
183
    }
184
}
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