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

atinc / ngx-tethys / d9ae709b-3c27-4b69-b125-b8b80b54f90b

pending completion
d9ae709b-3c27-4b69-b125-b8b80b54f90b

Pull #2757

circleci

mengshuicmq
fix: fix code review
Pull Request #2757: feat(color-picker): color-picker support disabled (#INFR-8645)

98 of 6315 branches covered (1.55%)

Branch coverage included in aggregate %.

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

2392 of 13661 relevant lines covered (17.51%)

83.12 hits per line

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

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

3
import { NgIf, 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,
×
14
    TemplateRef,
15
    ViewChild,
16
    ViewEncapsulation
1✔
17
} from '@angular/core';
1✔
18
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
19
import { ThyIconComponent } from 'ngx-tethys/icon';
20
import { ThyAutofocusDirective } from 'ngx-tethys/shared';
21
import { ThyInputDirective, ThyInputSize } from './input.directive';
22
import { InputBoolean } from 'ngx-tethys/core';
23

1✔
24
export const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR: any = {
25
    provide: NG_VALUE_ACCESSOR,
×
26
    useExisting: forwardRef(() => ThyInputComponent),
27
    multi: true
28
};
×
29

×
30
const noop = () => {};
×
31

×
32
const password = 'password';
×
33

×
34
/**
×
35
 * 内部集成输入框组件,建议 thy-input-group 和 thyInput 组合使用
×
36
 * @name thy-input
×
37
 * @order 50
×
38
 */
×
39
@Component({
×
40
    selector: 'thy-input',
41
    templateUrl: './input.component.html',
42
    providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR],
×
43
    encapsulation: ViewEncapsulation.None,
×
44
    host: {
×
45
        class: 'thy-input form-control',
46
        '[class.form-control-active]': 'focused',
47
        '[class.disabled]': 'disabled'
48
    },
49
    standalone: true,
×
50
    imports: [NgIf, NgTemplateOutlet, ThyInputDirective, ThyAutofocusDirective, FormsModule, ThyIconComponent]
51
})
52
export class ThyInputComponent implements ControlValueAccessor, OnInit {
×
53
    /**
54
     * Placeholder
55
     */
×
56
    @Input() placeholder = '';
57

58
    /**
×
59
     * 输入框大小
60
     * @type 'xs' | 'sm' | 'md' | 'default' | 'lg'
61
     * @default default
×
62
     */
63
    @Input() thySize: ThyInputSize;
64

×
65
    /**
×
66
     * 是否自动聚焦
×
67
     */
68
    @Input() @InputBoolean() thyAutofocus = false;
69

×
70
    /**
×
71
     * 输入框类型
×
72
     * @type 'number' | 'input'
73
     */
×
74
    @Input()
×
75
    set thyType(value: string) {
×
76
        this.type = value;
77
    }
78

×
79
    /**
80
     * @deprecated please use thyType
81
     */
×
82
    @Input() type: string;
83

1✔
84
    /**
85
     * 输入 Label 文本
86
     */
87
    @Input() thyLabelText: string;
1✔
88

89
    /**
90
     * 是否只读
91
     */
92
    @Input() @InputBoolean() readonly = false;
93

94
    /**
95
     * focus 聚焦事件
96
     */
97
    @Output() focus: EventEmitter<Event> = new EventEmitter<Event>();
98

99
    /**
100
     * blur 失焦事件
101
     */
102
    @Output() blur: EventEmitter<Event> = new EventEmitter<Event>();
1✔
103

104
    /**
105
     * 后置模板
106
     */
1✔
107
    @ContentChild('append') appendTemplate: TemplateRef<any>;
108

109
    /**
110
     * 前置模板
1✔
111
     */
112
    @ContentChild('prepend') prependTemplate: TemplateRef<any>;
113

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

116
    public _type = 'text';
117

118
    public value: string;
119

120
    public showLabel: boolean;
121

122
    public focused = false;
123

124
    public disabled = false;
125

126
    private onTouchedCallback: () => void = noop;
127

128
    private onChangeCallback: (_: any) => void = noop;
129

130
    constructor(private ngZone: NgZone, private elementRef: ElementRef) {}
131

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

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

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

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

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

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

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

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

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

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