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

atinc / ngx-tethys / edbc1d43-1648-411a-a6bc-f24c9aa3f654

27 Mar 2025 06:13AM UTC coverage: 90.236% (+0.06%) from 90.179%
edbc1d43-1648-411a-a6bc-f24c9aa3f654

push

circleci

web-flow
Merge pull request #3282 from atinc/v19.0.0-next

5598 of 6865 branches covered (81.54%)

Branch coverage included in aggregate %.

8 of 8 new or added lines in 7 files covered. (100.0%)

157 existing lines in 46 files now uncovered.

13357 of 14141 relevant lines covered (94.46%)

992.51 hits per line

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

89.47
/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 {
20
    IThyOptionGroupComponent,
1✔
21
    IThyOptionParentComponent,
22
    THY_OPTION_GROUP_COMPONENT,
580✔
23
    THY_OPTION_PARENT_COMPONENT
24
} from './option.token';
25

4,730✔
26
import { ThyIcon } from 'ngx-tethys/icon';
27

28
export class ThyOptionSelectionChangeEvent {
4,979✔
29
    constructor(
30
        public option: ThyOption,
31
        public isUserInput = false
9,975✔
32
    ) {}
33
}
34

4,730✔
35
export class ThyOptionVisibleChangeEvent {
36
    option: ThyOption;
37
}
4,911✔
38

39
/**
40
 * @private
953✔
41
 * @order 20
953✔
42
 */
953✔
43
@Component({
953✔
44
    selector: 'thy-option',
953✔
45
    templateUrl: './option.component.html',
953✔
46
    changeDetection: ChangeDetectionStrategy.OnPush,
953✔
47
    imports: [ThyIcon]
953✔
48
})
953✔
49
export class ThyOption extends SelectOptionBase implements OnDestroy, Highlightable {
953✔
50
    element = inject<ElementRef<HTMLElement>>(ElementRef);
953✔
51
    parent = inject(THY_OPTION_PARENT_COMPONENT, { optional: true })!;
52
    group = inject(THY_OPTION_GROUP_COMPONENT, { optional: true })!;
53
    private cdr = inject(ChangeDetectorRef);
166✔
54

55
    private _selected = false;
56
    private _hidden = false;
28✔
57
    private _disabled = false;
58

59
    @Input() thyValue: any;
×
60

×
UNCOV
61
    @Input() thyRawValue: any;
×
62

63
    @Input() thyLabelText: string;
64

65
    @Input() thyShowOptionCustom: boolean;
37✔
66

36✔
67
    @Input() thySearchKey: string;
36✔
68

36✔
69
    @HostBinding('class.thy-option-item') _isOptionItem = true;
70

71
    @ViewChild(TemplateRef, { static: true }) template: TemplateRef<any>;
72

92✔
73
    @Input({ transform: coerceBooleanProperty })
90✔
74
    @HostBinding(`class.disabled`)
48✔
75
    set thyDisabled(value: boolean) {
48✔
76
        this._disabled = value;
48✔
77
    }
78

79
    get thyDisabled(): boolean {
80
        return this._disabled;
81
    }
35✔
82

30✔
83
    get disabled(): boolean {
30✔
84
        return this.hidden || this._disabled;
30✔
85
    }
86

87
    @HostBinding('class.hidden')
88
    get hidden(): boolean {
40✔
89
        return this._hidden;
34✔
90
    }
34✔
91

34✔
92
    @HostBinding('attr.tabindex')
93
    get tabIndex(): string {
94
        return this.disabled ? '-1' : '0';
95
    }
12✔
96

7✔
97
    @HostBinding(`class.active`)
7✔
98
    get selected(): boolean {
7✔
99
        return this._selected;
100
    }
101

102
    @Output() readonly selectionChange: EventEmitter<ThyOptionSelectionChangeEvent> = new EventEmitter();
52✔
103
    @Output() readonly visibleChange: EventEmitter<ThyOptionVisibleChangeEvent> = new EventEmitter();
8✔
104

1✔
105
    constructor() {
106
        super();
107
    }
7✔
108

109
    getHostElement(): HTMLElement {
110
        return this.element.nativeElement;
111
    }
44✔
112

11✔
113
    @HostListener('click', ['$event'])
114
    onClick(event: Event) {
115
        this.selectViaInteraction();
33✔
116
    }
117

118
    @HostListener('keydown', ['$event'])
119
    handleKeydown(event: KeyboardEvent): void {
120
        if ((event.keyCode === ENTER || event.keyCode === SPACE) && !hasModifierKey(event)) {
118✔
121
            this.selectViaInteraction();
118✔
122
            event.preventDefault();
123
        }
124
    }
48✔
125

48✔
126
    selectViaInteraction(): void {
127
        if (!this.disabled) {
UNCOV
128
            this._selected = this.parent.isMultiple ? !this._selected : true;
×
129
            this.cdr.markForCheck();
130
            this.emitSelectionChangeEvent(true);
78✔
131
        }
114✔
132
    }
133

134
    select(event?: Event): void {
1✔
135
        if (!this.disabled) {
1✔
136
            if (!this._selected) {
137
                this._selected = true;
138
                this.emitSelectionChangeEvent();
139
                this.cdr.markForCheck();
140
            }
141
        }
142
    }
143

144
    deselect(): void {
145
        if (this._selected || this.disabled) {
146
            this._selected = false;
147
            this.emitSelectionChangeEvent();
148
            this.cdr.markForCheck();
149
        }
150
    }
151

152
    hideOption() {
153
        if (!this._hidden) {
1✔
154
            this._hidden = true;
155
            this.visibleChange.emit({ option: this });
156
            this.cdr.markForCheck();
157
        }
158
    }
159

160
    showOption() {
161
        if (this._hidden) {
162
            this._hidden = false;
163
            this.visibleChange.emit({ option: this });
164
            this.cdr.markForCheck();
165
        }
166
    }
167

168
    matchSearchText(searchText: string): boolean {
169
        if (this.thySearchKey) {
170
            if (this.thySearchKey.toLowerCase().indexOf(searchText.toLowerCase()) >= 0) {
171
                return true;
172
            } else {
173
                return false;
174
            }
175
        } else {
176
            if (this.thyLabelText.toLowerCase().indexOf(searchText.toLowerCase()) >= 0) {
177
                return true;
178
            } else {
179
                return false;
180
            }
181
        }
182
    }
183

184
    setActiveStyles(): void {
185
        this.getHostElement().classList.add('hover');
186
        this.cdr.markForCheck();
187
    }
188

189
    setInactiveStyles(): void {
190
        this.getHostElement().classList.remove('hover');
191
        this.cdr.markForCheck();
192
    }
193

194
    getLabel(): string {
195
        return '';
196
    }
197

198
    private emitSelectionChangeEvent(isUserInput = false): void {
199
        this.selectionChange.emit(new ThyOptionSelectionChangeEvent(this, isUserInput));
200
    }
201

202
    ngOnDestroy() {}
203
}
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

© 2026 Coveralls, Inc