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

atinc / ngx-tethys / 68ef226c-f83e-44c1-b8ed-e420a83c5d84

28 May 2025 10:31AM UTC coverage: 10.352% (-80.0%) from 90.316%
68ef226c-f83e-44c1-b8ed-e420a83c5d84

Pull #3460

circleci

pubuzhixing8
chore: xxx
Pull Request #3460: refactor(icon): migrate signal input #TINFR-1476

132 of 6823 branches covered (1.93%)

Branch coverage included in aggregate %.

10 of 14 new or added lines in 1 file covered. (71.43%)

11648 existing lines in 344 files now uncovered.

2078 of 14525 relevant lines covered (14.31%)

6.69 hits per line

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

4.26
/src/shared/option/option.component.ts
1
import {
2
    Component,
3
    Input,
4
    TemplateRef,
5
    ViewChild,
6
    ChangeDetectionStrategy,
7
    HostBinding,
8
    HostListener,
9
    ElementRef,
×
UNCOV
10
    ChangeDetectorRef,
×
UNCOV
11
    EventEmitter,
×
12
    OnDestroy,
13
    Output,
14
    inject
15
} from '@angular/core';
16
import { Highlightable } from '@angular/cdk/a11y';
17
import { SelectOptionBase } from './select-option-base';
18
import { ENTER, SPACE, coerceBooleanProperty, hasModifierKey } from 'ngx-tethys/util';
19
import { THY_OPTION_PARENT_COMPONENT } from './option.token';
20

1✔
21
import { ThyIcon } from 'ngx-tethys/icon';
UNCOV
22

×
23
export class ThyOptionSelectionChangeEvent {
24
    constructor(
UNCOV
25
        public option: ThyOption,
×
26
        public isUserInput = false
27
    ) {}
UNCOV
28
}
×
29

30
export class ThyOptionVisibleChangeEvent {
UNCOV
31
    option: ThyOption;
×
32
}
33

UNCOV
34
/**
×
35
 * @private
36
 * @order 20
UNCOV
37
 */
×
38
@Component({
39
    selector: 'thy-option',
UNCOV
40
    templateUrl: './option.component.html',
×
UNCOV
41
    changeDetection: ChangeDetectionStrategy.OnPush,
×
UNCOV
42
    imports: [ThyIcon]
×
UNCOV
43
})
×
UNCOV
44
export class ThyOption extends SelectOptionBase implements OnDestroy, Highlightable {
×
UNCOV
45
    element = inject<ElementRef<HTMLElement>>(ElementRef);
×
UNCOV
46
    parent = inject(THY_OPTION_PARENT_COMPONENT, { optional: true })!;
×
UNCOV
47
    private cdr = inject(ChangeDetectorRef);
×
UNCOV
48

×
UNCOV
49
    private _selected = false;
×
50
    private _hidden = false;
51
    private _disabled = false;
UNCOV
52

×
53
    @Input() thyValue: any;
54

UNCOV
55
    @Input() thyRawValue: any;
×
56

57
    @Input() thyLabelText: string;
58

×
59
    @Input() thyShowOptionCustom: boolean;
×
60

×
61
    @Input() thySearchKey: string;
62

63
    @HostBinding('class.thy-option-item') _isOptionItem = true;
UNCOV
64

×
UNCOV
65
    @ViewChild(TemplateRef, { static: true }) template: TemplateRef<any>;
×
UNCOV
66

×
UNCOV
67
    @Input({ transform: coerceBooleanProperty })
×
68
    @HostBinding(`class.disabled`)
69
    set thyDisabled(value: boolean) {
70
        this._disabled = value;
UNCOV
71
    }
×
UNCOV
72

×
UNCOV
73
    get thyDisabled(): boolean {
×
UNCOV
74
        return this._disabled;
×
UNCOV
75
    }
×
76

77
    get disabled(): boolean {
78
        return this.hidden || this._disabled;
79
    }
UNCOV
80

×
UNCOV
81
    @HostBinding('class.hidden')
×
UNCOV
82
    get hidden(): boolean {
×
UNCOV
83
        return this._hidden;
×
84
    }
85

86
    @HostBinding('attr.tabindex')
UNCOV
87
    get tabIndex(): string {
×
UNCOV
88
        return this.disabled ? '-1' : '0';
×
UNCOV
89
    }
×
UNCOV
90

×
91
    @HostBinding(`class.active`)
92
    get selected(): boolean {
93
        return this._selected;
UNCOV
94
    }
×
UNCOV
95

×
UNCOV
96
    @Output() readonly selectionChange: EventEmitter<ThyOptionSelectionChangeEvent> = new EventEmitter();
×
UNCOV
97
    @Output() readonly visibleChange: EventEmitter<ThyOptionVisibleChangeEvent> = new EventEmitter();
×
98

99
    constructor() {
100
        super();
UNCOV
101
    }
×
UNCOV
102

×
UNCOV
103
    getHostElement(): HTMLElement {
×
104
        return this.element.nativeElement;
105
    }
UNCOV
106

×
107
    @HostListener('click', ['$event'])
108
    onClick(event: Event) {
109
        this.selectViaInteraction();
UNCOV
110
    }
×
UNCOV
111

×
112
    @HostListener('keydown', ['$event'])
113
    handleKeydown(event: KeyboardEvent): void {
UNCOV
114
        if ((event.keyCode === ENTER || event.keyCode === SPACE) && !hasModifierKey(event)) {
×
115
            this.selectViaInteraction();
116
            event.preventDefault();
117
        }
118
    }
UNCOV
119

×
UNCOV
120
    selectViaInteraction(): void {
×
121
        if (!this.disabled) {
122
            this._selected = this.parent.isMultiple ? !this._selected : true;
UNCOV
123
            this.cdr.markForCheck();
×
UNCOV
124
            this.emitSelectionChangeEvent(true);
×
125
        }
126
    }
127

×
128
    select(event?: Event): void {
129
        if (!this.disabled) {
×
UNCOV
130
            if (!this._selected) {
×
131
                this._selected = true;
132
                this.emitSelectionChangeEvent();
133
                this.cdr.markForCheck();
1✔
134
            }
1✔
135
        }
136
    }
137

138
    deselect(): void {
139
        if (this._selected || this.disabled) {
140
            this._selected = false;
141
            this.emitSelectionChangeEvent();
142
            this.cdr.markForCheck();
143
        }
144
    }
145

146
    hideOption() {
147
        if (!this._hidden) {
148
            this._hidden = true;
149
            this.visibleChange.emit({ option: this });
150
            this.cdr.markForCheck();
151
        }
152
    }
1✔
153

154
    showOption() {
155
        if (this._hidden) {
156
            this._hidden = false;
157
            this.visibleChange.emit({ option: this });
158
            this.cdr.markForCheck();
159
        }
160
    }
161

162
    matchSearchText(searchText: string): boolean {
163
        if (this.thySearchKey) {
164
            if (this.thySearchKey.toLowerCase().indexOf(searchText.toLowerCase()) >= 0) {
165
                return true;
166
            } else {
167
                return false;
168
            }
169
        } else {
170
            if (this.thyLabelText.toLowerCase().indexOf(searchText.toLowerCase()) >= 0) {
171
                return true;
172
            } else {
173
                return false;
174
            }
175
        }
176
    }
177

178
    setActiveStyles(): void {
179
        this.getHostElement().classList.add('hover');
180
        this.cdr.markForCheck();
181
    }
182

183
    setInactiveStyles(): void {
184
        this.getHostElement().classList.remove('hover');
185
        this.cdr.markForCheck();
186
    }
187

188
    getLabel(): string {
189
        return '';
190
    }
191

192
    private emitSelectionChangeEvent(isUserInput = false): void {
193
        this.selectionChange.emit(new ThyOptionSelectionChangeEvent(this, isUserInput));
194
    }
195

196
    ngOnDestroy() {}
197
}
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