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

atinc / ngx-tethys / cd64db52-e563-41a3-85f3-a0adb87ce135

30 Oct 2024 08:03AM UTC coverage: 90.402% (-0.04%) from 90.438%
cd64db52-e563-41a3-85f3-a0adb87ce135

push

circleci

web-flow
refactor: refactor constructor to the inject function (#3222)

5503 of 6730 branches covered (81.77%)

Branch coverage included in aggregate %.

422 of 429 new or added lines in 170 files covered. (98.37%)

344 existing lines in 81 files now uncovered.

13184 of 13941 relevant lines covered (94.57%)

997.19 hits per line

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

91.43
/src/select/native-select/native-select.component.ts
1
import { Component, forwardRef, HostBinding, Input, OnInit, inject } from '@angular/core';
2
import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
3
import { TabIndexDisabledControlValueAccessorMixin } from 'ngx-tethys/core';
4
import { coerceBooleanProperty, elementMatchClosest } from 'ngx-tethys/util';
5

6
import { ElementRef, ViewChild } from '@angular/core';
7
import { useHostRenderer } from '@tethys/cdk/dom';
8
import { ThyIcon } from 'ngx-tethys/icon';
9
import { ThyInputDirective } from 'ngx-tethys/input';
10

11
export type InputSize = 'xs' | 'sm' | 'md' | 'lg' | '';
1✔
12

13
const noop = () => {};
14

15
/**
16
 * 下拉选择
17
 * @name thy-native-select
1✔
18
 * @order 20
19
 */
13✔
20
@Component({
21
    selector: 'thy-native-select',
22
    templateUrl: './native-select.component.html',
18✔
23
    providers: [
9✔
24
        {
25
            provide: NG_VALUE_ACCESSOR,
26
            useExisting: forwardRef(() => ThyNativeSelect),
27
            multi: true
19✔
28
        }
29
    ],
30
    standalone: true,
10✔
31
    imports: [ThyInputDirective, FormsModule, ThyIcon],
10✔
32
    host: {
33
        '[attr.tabindex]': 'tabIndex',
10✔
34
        '(focus)': 'onFocus($event)',
10✔
35
        '(blur)': 'onBlur($event)'
10✔
36
    }
10✔
37
})
10✔
38
export class ThyNativeSelect extends TabIndexDisabledControlValueAccessorMixin implements ControlValueAccessor, OnInit {
10✔
39
    private elementRef = inject(ElementRef);
40

UNCOV
41
    @ViewChild('select', { static: true }) selectElement: ElementRef<any>;
×
UNCOV
42

×
43
    // The internal data model
44
    _innerValue: any = null;
45
    _disabled = false;
9!
46
    _size: InputSize;
9✔
47
    _expandOptions = false;
48

49
    private hostRenderer = useHostRenderer();
2✔
50

1✔
51
    @HostBinding('class.thy-select') _isSelect = true;
52

1✔
53
    @Input()
54
    set thySize(value: InputSize) {
55
        this._size = value;
1✔
56
    }
57

58
    @Input() name: string;
1✔
59

1✔
60
    @Input({ transform: coerceBooleanProperty }) thyAllowClear = false;
1✔
61

62
    writeValue(obj: any): void {
1✔
63
        if (obj !== this._innerValue) {
1✔
64
            this._innerValue = obj;
65
        }
66
    }
67

68
    setDisabledState?(isDisabled: boolean): void {
69
        this._disabled = isDisabled;
70
    }
71

1✔
72
    constructor() {
73
        super();
74
    }
75

76
    ngModelChange() {
77
        this.onChangeFn(this._innerValue);
78
        this.onTouchedFn();
10✔
79
    }
80

81
    ngOnInit() {
82
        const classes = this._size ? [`thy-select-${this._size}`] : [];
83
        this.hostRenderer.updateClass(classes);
84
    }
85

86
    onBlur(event: FocusEvent) {
87
        if (elementMatchClosest(event?.relatedTarget as HTMLElement, 'thy-native-select')) {
88
            return;
89
        }
90
        this.onTouchedFn();
91
    }
92

93
    onFocus(event?: Event) {
94
        this.selectElement.nativeElement.focus();
95
    }
96

97
    clearSelectValue(event: Event) {
98
        event.stopPropagation();
99
        this._innerValue = '';
100
        this.onChangeFn(this._innerValue);
101
    }
102
}
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