• 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

13.79
/src/input/input-search.component.ts
1
import {
2
    AbstractControlValueAccessor,
3
    Constructor,
4
    InputBoolean,
5
    mixinDisabled,
6
    mixinInitialized,
7
    mixinTabIndex,
8
    ThyCanDisable,
9
    ThyHasTabIndex,
10
    ThyInitialized
11
} from 'ngx-tethys/core';
12

1✔
13
import { NgIf } from '@angular/common';
14
import {
×
15
    ChangeDetectionStrategy,
16
    ChangeDetectorRef,
17
    Component,
1✔
18
    ElementRef,
1✔
19
    EventEmitter,
20
    forwardRef,
21
    Input,
22
    OnInit,
23
    Output,
24
    ViewChild,
1✔
25
    ViewEncapsulation
26
} from '@angular/core';
×
27
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
×
28
import { useHostRenderer } from '@tethys/cdk/dom';
29
import { ThyIconComponent } from 'ngx-tethys/icon';
30
import { ThyAutofocusDirective } from 'ngx-tethys/shared';
×
31
import { ThyInputDirective, ThyInputSize } from './input.directive';
×
32

33
import { elementMatchClosest } from 'ngx-tethys/util';
34

×
35
export type ThyInputSearchTheme = 'default' | 'ellipse' | 'transparent' | '';
×
36
export type ThyInputSearchIconPosition = 'before' | 'after';
×
37

×
38
export const CUSTOM_INPUT_SEARCH_CONTROL_VALUE_ACCESSOR: any = {
×
39
    provide: NG_VALUE_ACCESSOR,
×
40
    useExisting: forwardRef(() => ThyInputSearchComponent),
×
41
    multi: true
×
42
};
×
43

×
44
const noop = () => {};
×
45

×
46
const _MixinBase: Constructor<ThyHasTabIndex> &
47
    Constructor<ThyInitialized> &
48
    Constructor<ThyCanDisable> &
×
49
    typeof AbstractControlValueAccessor = mixinInitialized(mixinTabIndex(mixinDisabled(AbstractControlValueAccessor)));
×
50

51
/**
×
52
 * 搜索输入框
×
53
 * @name thy-input-search
×
54
 * @order 30
55
 */
56
@Component({
57
    selector: 'thy-input-search',
×
58
    templateUrl: './input-search.component.html',
×
59
    providers: [CUSTOM_INPUT_SEARCH_CONTROL_VALUE_ACCESSOR],
60
    encapsulation: ViewEncapsulation.None,
61
    changeDetection: ChangeDetectionStrategy.OnPush,
×
62
    host: {
63
        class: 'thy-input form-control thy-input-search',
64
        '[class.thy-input-search-ellipse]': 'thyTheme === "ellipse"',
×
65
        '[class.thy-input-search-transparent]': 'thyTheme === "transparent"',
66
        '[class.thy-input-search-before-with-clear]': 'searchText && iconPosition === "before"',
67
        '[class.form-control-active]': 'focused',
×
68
        '[attr.tabindex]': 'tabIndex',
×
69
        '(focus)': 'onFocus($event)',
×
70
        '(blur)': 'onBlur($event)'
×
71
    },
×
72
    standalone: true,
73
    imports: [NgIf, ThyIconComponent, ThyInputDirective, ThyAutofocusDirective, FormsModule]
×
74
})
×
75
export class ThyInputSearchComponent extends _MixinBase implements ControlValueAccessor, OnInit {
×
76
    @ViewChild('input', { static: true }) inputElement: ElementRef<any>;
×
77

78
    private hostRenderer = useHostRenderer();
79

×
80
    public disabled = false;
81

×
82
    public autoFocus = false;
×
83

84
    public iconPosition: ThyInputSearchIconPosition = 'before';
×
85

86
    searchText: string;
87

×
88
    focused = false;
89

1✔
90
    /**
91
     * 搜索框 name 属性
92
     */
93
    @Input() name = '';
1✔
94

95
    /**
96
     * 搜索框 Placeholder
97
     */
98
    @Input() placeholder = '';
99

100
    /**
101
     * 搜索框风格
102
     * @type 'default' | 'ellipse' | 'transparent'
103
     * @default default
104
     */
105
    @Input() thyTheme: ThyInputSearchTheme;
1✔
106

107
    /**
108
     * 是否自动聚焦
109
     * @default false
110
     */
1✔
111
    @Input()
112
    @InputBoolean()
113
    set thySearchFocus(value: boolean) {
114
        this.autoFocus = value;
115
        this.focused = value;
116
    }
117

118
    /**
119
     * 搜索图标位置,当传入 after 时,搜索图标在输入框后方显示,有内容时显示为关闭按钮
120
     * @type
121
     */
122
    @Input() set thyIconPosition(value: ThyInputSearchIconPosition) {
123
        this.iconPosition = value || 'before';
124
        this.updateClasses();
125
    }
126

127
    /**
128
     * 输入框大小
129
     * @type 'xs' | 'sm' | 'md' | 'default' | 'lg'
130
     */
131
    @Input() thySize: ThyInputSize;
132

133
    /**
134
     * @deprecated please use thyClear
135
     */
136
    @Output() clear: EventEmitter<Event> = new EventEmitter<Event>();
137

138
    /**
139
     * 清除搜索事件
140
     */
141
    @Output() thyClear: EventEmitter<Event> = new EventEmitter<Event>();
142

143
    constructor(private cdr: ChangeDetectorRef, private elementRef: ElementRef) {
144
        super();
145
    }
146

147
    ngOnInit(): void {
148
        super.ngOnInit();
149
        this.updateClasses(true);
150
    }
151

152
    updateClasses(forceUpdate = false) {
153
        if (this.initialized || forceUpdate) {
154
            this.hostRenderer.updateClass([`thy-input-search-${this.iconPosition}`]);
155
        }
156
    }
157

158
    writeValue(value: any): void {
159
        this.searchText = value;
160
        this.cdr.markForCheck();
161
    }
162

163
    setDisabledState?(isDisabled: boolean): void {
164
        this.disabled = isDisabled;
165
    }
166

167
    searchModelChange() {
168
        this.onChangeFn(this.searchText);
169
    }
170

171
    clearSearchText(event: Event) {
172
        const element = this.elementRef.nativeElement.querySelector('.input-search-control');
173
        element.focus();
174
        event.stopPropagation();
175
        if (this.disabled) {
176
            return;
177
        }
178
        this.searchText = '';
179
        this.onChangeFn(this.searchText);
180
        this.clear.emit(event);
181
        this.thyClear.emit(event);
182
    }
183

184
    onBlur(event?: FocusEvent) {
185
        this.focused = false;
186
        // Tab 聚焦后自动聚焦到 input 输入框,此分支下直接返回,无需触发 onTouchedFn
187
        if (elementMatchClosest(event?.relatedTarget as HTMLElement, 'thy-input-search')) {
188
            return;
189
        }
190
        this.onTouchedFn();
191
    }
192

193
    onFocus(event?: Event) {
194
        this.inputElement.nativeElement.focus();
195
    }
196
}
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