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

atinc / ngx-tethys / 8a6ba229-c82f-4a21-a1ed-95461f2ad66c

04 Sep 2023 08:37AM UTC coverage: 90.196% (-0.004%) from 90.2%
8a6ba229-c82f-4a21-a1ed-95461f2ad66c

Pull #2829

circleci

cmm-va
fix: delete f
Pull Request #2829: fix: add tabIndex

5164 of 6386 branches covered (0.0%)

Branch coverage included in aggregate %.

78 of 78 new or added lines in 26 files covered. (100.0%)

13024 of 13779 relevant lines covered (94.52%)

971.69 hits per line

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

84.91
/src/radio/group/radio-group.component.ts
1
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, forwardRef, HostBinding, Input, OnInit } from '@angular/core';
2
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
3
import { useHostRenderer } from '@tethys/cdk/dom';
4
import { InputBoolean } from 'ngx-tethys/core';
5

6
import { ThyRadioButtonComponent } from '../button/radio-button.component';
7
import { ThyRadioComponent } from '../radio.component';
8

1✔
9
const buttonGroupSizeMap = {
10
    sm: ['btn-group-sm'],
11
    lg: ['btn-group-lg']
12
};
1✔
13

14
const radioGroupLayoutMap = {
15
    flex: ['radio-group-layout-flex']
16
};
17

18
/**
19
 * @name thy-radio-group
1✔
20
 * @order 20
21
 */
8✔
22
@Component({
23
    selector: 'thy-radio-group',
24
    templateUrl: './radio-group.component.html',
×
25
    providers: [
26
        {
27
            provide: NG_VALUE_ACCESSOR,
×
28
            useExisting: forwardRef(() => ThyRadioGroupComponent),
29
            multi: true
30
        }
5✔
31
    ],
5✔
32
    host: {
5✔
33
        '[attr.tabindex]': `-1`
5✔
34
    },
5✔
35
    changeDetection: ChangeDetectionStrategy.OnPush,
5✔
36
    standalone: true
5✔
37
})
5✔
38
export class ThyRadioGroupComponent implements ControlValueAccessor, OnInit {
39
    @HostBinding('class.thy-radio-group') thyRadioGroup = true;
40

15✔
41
    @HostBinding('class.btn-group') isButtonGroup = false;
15✔
42

43
    @HostBinding('class.btn-group-outline-default')
44
    isButtonGroupOutline = false;
12✔
45

12✔
46
    private _size: string;
21✔
47

48
    private _layout: string;
12!
49

×
50
    /**
51
     * 大小
12✔
52
     * @type sm | md | lg
12✔
53
     * @default md
54
     */
55
    @Input()
12✔
56
    set thySize(size: string) {
57
        this._size = size;
58
    }
5✔
59

60
    @Input()
61
    set thyLayout(layout: string) {
5✔
62
        this._layout = layout;
63
    }
64

5✔
65
    _innerValue: string | number;
×
66

67
    radios: Array<ThyRadioComponent | ThyRadioButtonComponent> = [];
68

69
    private hostRenderer = useHostRenderer();
5!
70

5✔
71
    /**
5✔
72
     * 是否禁用单选组合框
73
     * @default false
74
     */
75
    @Input()
8✔
76
    @InputBoolean()
77
    set thyDisabled(value: boolean) {
78
        this.setDisabledState(value);
8✔
79
    }
8✔
80

2✔
81
    onChange: (_: string) => void = () => null;
82
    onTouched: () => void = () => null;
8!
83

×
84
    constructor(private changeDetectorRef: ChangeDetectorRef) {}
85

8✔
86
    addRadio(radio: ThyRadioComponent | ThyRadioButtonComponent): void {
87
        this.radios.push(radio);
1✔
88
        radio.thyChecked = radio.thyValue === this._innerValue;
89
    }
90

1✔
91
    updateValue(value: string, emit: boolean): void {
92
        this._innerValue = value;
93
        this.radios.forEach(radio => {
94
            radio.thyChecked = radio.thyValue === this._innerValue;
95
        });
96
        if (emit) {
97
            this.onChange(value);
98
        }
99
        this.onTouched();
1✔
100
        this.changeDetectorRef.detectChanges();
101
    }
102

103
    writeValue(value: any): void {
104
        this.updateValue(value, false);
1✔
105
    }
106

107
    registerOnChange(fn: any): void {
108
        this.onChange = fn;
109
    }
110

111
    registerOnTouched(fn: any): void {
5✔
112
        this.onTouched = fn;
113
    }
114

115
    setDisabledState?(isDisabled: boolean): void {
116
        this.radios.forEach(radio => {
117
            radio.setDisabledState(isDisabled);
118
        });
119
    }
120

121
    setGroup() {
122
        if (!this.isButtonGroup && !this.isButtonGroupOutline) {
123
            this.isButtonGroup = true;
124
            this.isButtonGroupOutline = true;
125
        }
126
    }
127

128
    ngOnInit() {
129
        this._setClasses();
130
    }
131

132
    private _setClasses() {
133
        const classNames: string[] = [];
134
        if (buttonGroupSizeMap[this._size]) {
135
            classNames.push(buttonGroupSizeMap[this._size]);
136
        }
137
        if (radioGroupLayoutMap[this._layout]) {
138
            classNames.push(radioGroupLayoutMap[this._layout]);
139
        }
140
        this.hostRenderer.updateClass(classNames);
141
    }
142
}
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