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

atinc / ngx-tethys / 82f575a8-2f12-4689-80e6-398f6f1685a3

15 Aug 2024 08:19AM UTC coverage: 90.473%. Remained the same
82f575a8-2f12-4689-80e6-398f6f1685a3

push

circleci

web-flow
build: bump prettier to 3.3.3 and other deps, refactor notify use @if (#3152)

5502 of 6726 branches covered (81.8%)

Branch coverage included in aggregate %.

112 of 116 new or added lines in 57 files covered. (96.55%)

59 existing lines in 15 files now uncovered.

13254 of 14005 relevant lines covered (94.64%)

997.41 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,
×
11
    EventEmitter,
117✔
12
    OnDestroy,
117✔
13
    Output,
14
    Inject,
15
    Optional
16
} from '@angular/core';
17
import { Highlightable } from '@angular/cdk/a11y';
18
import { SelectOptionBase } from './select-option-base';
19
import { ENTER, SPACE, coerceBooleanProperty, hasModifierKey } from 'ngx-tethys/util';
20
import {
21
    IThyOptionGroupComponent,
1✔
22
    IThyOptionParentComponent,
23
    THY_OPTION_GROUP_COMPONENT,
581✔
24
    THY_OPTION_PARENT_COMPONENT
25
} from './option.token';
26
import { NgIf } from '@angular/common';
4,730✔
27
import { ThyIcon } from 'ngx-tethys/icon';
28

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

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

40
/**
41
 * @private
954✔
42
 * @order 20
954✔
43
 */
954✔
44
@Component({
954✔
45
    selector: 'thy-option',
954✔
46
    templateUrl: './option.component.html',
954✔
47
    changeDetection: ChangeDetectionStrategy.OnPush,
954✔
48
    standalone: true,
954✔
49
    imports: [NgIf, ThyIcon]
954✔
50
})
954✔
51
export class ThyOption extends SelectOptionBase implements OnDestroy, Highlightable {
954✔
52
    private _selected = false;
53
    private _hidden = false;
54
    private _disabled = false;
166✔
55

56
    @Input() thyValue: any;
57

28✔
58
    @Input() thyRawValue: any;
59

UNCOV
60
    @Input() thyLabelText: string;
×
UNCOV
61

×
UNCOV
62
    @Input() thyShowOptionCustom: boolean;
×
63

64
    @Input() thySearchKey: string;
65

66
    @HostBinding('class.thy-option-item') _isOptionItem = true;
37✔
67

36✔
68
    @ViewChild(TemplateRef, { static: true }) template: TemplateRef<any>;
36✔
69

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

48✔
76
    get thyDisabled(): boolean {
48✔
77
        return this._disabled;
48✔
78
    }
79

80
    get disabled(): boolean {
81
        return this.hidden || this._disabled;
82
    }
35✔
83

30✔
84
    @HostBinding('class.hidden')
30✔
85
    get hidden(): boolean {
30✔
86
        return this._hidden;
87
    }
88

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

94
    @HostBinding(`class.active`)
95
    get selected(): boolean {
96
        return this._selected;
12✔
97
    }
7✔
98

7✔
99
    @Output() readonly selectionChange: EventEmitter<ThyOptionSelectionChangeEvent> = new EventEmitter();
7✔
100
    @Output() readonly visibleChange: EventEmitter<ThyOptionVisibleChangeEvent> = new EventEmitter();
101

102
    constructor(
103
        public element: ElementRef<HTMLElement>,
52✔
104
        @Optional() @Inject(THY_OPTION_PARENT_COMPONENT) public parent: IThyOptionParentComponent,
8✔
105
        @Optional() @Inject(THY_OPTION_GROUP_COMPONENT) public group: IThyOptionGroupComponent,
1✔
106
        private cdr: ChangeDetectorRef
107
    ) {
108
        super();
7✔
109
    }
110

111
    getHostElement(): HTMLElement {
112
        return this.element.nativeElement;
44✔
113
    }
11✔
114

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

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

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

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

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

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

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

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

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

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

196
    getLabel(): string {
197
        return '';
198
    }
199

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

204
    ngOnDestroy() {}
205
}
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