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

atinc / ngx-tethys / 583880b9-7292-442c-8670-32bad4efd72a

07 Sep 2023 03:07AM UTC coverage: 90.196% (+0.005%) from 90.191%
583880b9-7292-442c-8670-32bad4efd72a

Pull #2829

circleci

cmm-va
Merge branch 'cmm/#INFR-9451' of github.com:atinc/ngx-tethys into cmm/#INFR-9451
Pull Request #2829: fix: add tabIndex

5163 of 6383 branches covered (0.0%)

Branch coverage included in aggregate %.

62 of 62 new or added lines in 13 files covered. (100.0%)

13035 of 13793 relevant lines covered (94.5%)

970.71 hits per line

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

91.67
/src/select/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, InputBoolean } from 'ngx-tethys/core';
4
import { elementMatchClosest } from 'ngx-tethys/util';
5

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

12
export type InputSize = 'xs' | 'sm' | 'md' | 'lg' | '';
13

1✔
14
const noop = () => {};
15

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

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

9!
48
    private hostRenderer = useHostRenderer();
9✔
49

50
    @HostBinding('class.thy-select') _isSelect = true;
51

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

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

59
    @Input() @InputBoolean() thyAllowClear = false;
60

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

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

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

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

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

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

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

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