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

atinc / ngx-tethys / 0b71bffa-d18d-4775-9f80-dad8a7c0cf39

11 Oct 2024 05:59AM UTC coverage: 90.431% (-0.04%) from 90.472%
0b71bffa-d18d-4775-9f80-dad8a7c0cf39

push

circleci

minlovehua
build: update package-lock.json to fix ci

5511 of 6738 branches covered (81.79%)

Branch coverage included in aggregate %.

13219 of 13974 relevant lines covered (94.6%)

994.15 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 } 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
    @ViewChild('select', { static: true }) selectElement: ElementRef<any>;
40

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

9✔
47
    private hostRenderer = useHostRenderer();
48

49
    @HostBinding('class.thy-select') _isSelect = true;
2✔
50

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

1✔
56
    @Input() name: string;
57

58
    @Input({ transform: coerceBooleanProperty }) thyAllowClear = false;
1✔
59

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

1✔
66
    setDisabledState?(isDisabled: boolean): void {
67
        this._disabled = isDisabled;
68
    }
69

70
    constructor(private elementRef: ElementRef) {
71
        super();
72
    }
73

1✔
74
    ngModelChange() {
75
        this.onChangeFn(this._innerValue);
76
        this.onTouchedFn();
77
    }
78

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

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

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

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