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

atinc / ngx-tethys / 07aa0f59-e5f9-4b7e-9755-2f67bea3c0d5

21 Apr 2025 10:25AM UTC coverage: 90.271% (+0.001%) from 90.27%
07aa0f59-e5f9-4b7e-9755-2f67bea3c0d5

Pull #3341

circleci

minlovehua
docs(cdk): merge imports
Pull Request #3341: refactor(all): resolve 30 circular denpendencies TINFR-1830

5614 of 6878 branches covered (81.62%)

Branch coverage included in aggregate %.

89 of 94 new or added lines in 38 files covered. (94.68%)

64 existing lines in 12 files now uncovered.

13370 of 14152 relevant lines covered (94.47%)

921.99 hits per line

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

89.36
/src/shared/option/option.component.ts
1
import {
2
    Component,
3
    Input,
4
    TemplateRef,
5
    ViewChild,
6
    ChangeDetectionStrategy,
7
    HostBinding,
8
    HostListener,
9
    ElementRef,
×
10
    ChangeDetectorRef,
117✔
11
    EventEmitter,
117✔
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';
22

580✔
23
export class ThyOptionSelectionChangeEvent {
24
    constructor(
25
        public option: ThyOption,
4,730✔
26
        public isUserInput = false
27
    ) {}
28
}
4,979✔
29

30
export class ThyOptionVisibleChangeEvent {
31
    option: ThyOption;
9,975✔
32
}
33

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

953✔
49
    private _selected = false;
953✔
50
    private _hidden = false;
51
    private _disabled = false;
52

166✔
53
    @Input() thyValue: any;
54

55
    @Input() thyRawValue: any;
28✔
56

57
    @Input() thyLabelText: string;
UNCOV
58

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

×
61
    @Input() thySearchKey: string;
62

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

37✔
65
    @ViewChild(TemplateRef, { static: true }) template: TemplateRef<any>;
36✔
66

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

90✔
73
    get thyDisabled(): boolean {
48✔
74
        return this._disabled;
48✔
75
    }
48✔
76

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

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

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

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

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

99
    constructor() {
100
        super();
101
    }
52✔
102

8✔
103
    getHostElement(): HTMLElement {
1✔
104
        return this.element.nativeElement;
105
    }
106

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

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

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

×
128
    select(event?: Event): void {
129
        if (!this.disabled) {
78✔
130
            if (!this._selected) {
114✔
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