• 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

7.94
/src/radio/group/radio-group.component.ts
1
import {
2
    AfterContentInit,
3
    ChangeDetectionStrategy,
4
    ChangeDetectorRef,
5
    Component,
6
    forwardRef,
7
    HostBinding,
8
    inject,
9
    input,
1✔
10
    OnChanges,
11
    OnInit,
12
    SimpleChanges
13
} from '@angular/core';
1✔
14
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
15
import { useHostRenderer } from '@tethys/cdk/dom';
16

17
import { coerceBooleanProperty } from 'ngx-tethys/util';
18
import { ThyRadioButton } from '../button/radio-button.component';
19
import { ThyRadio } from '../radio.component';
20
import { IThyRadioGroupComponent, THY_RADIO_GROUP_COMPONENT } from '../radio.token';
1✔
21

UNCOV
22
const buttonGroupSizeMap = {
×
UNCOV
23
    sm: ['btn-group-sm'],
×
UNCOV
24
    lg: ['btn-group-lg']
×
UNCOV
25
};
×
UNCOV
26

×
UNCOV
27
const radioGroupLayoutMap = {
×
UNCOV
28
    flex: ['radio-group-layout-flex']
×
UNCOV
29
};
×
UNCOV
30

×
UNCOV
31
/**
×
UNCOV
32
 * @name thy-radio-group
×
33
 * @order 20
34
 */
UNCOV
35
@Component({
×
UNCOV
36
    selector: 'thy-radio-group',
×
37
    templateUrl: './radio-group.component.html',
38
    providers: [
UNCOV
39
        {
×
UNCOV
40
            provide: NG_VALUE_ACCESSOR,
×
UNCOV
41
            useExisting: forwardRef(() => ThyRadioGroup),
×
42
            multi: true
UNCOV
43
        },
×
44
        {
×
45
            provide: THY_RADIO_GROUP_COMPONENT,
UNCOV
46
            useExisting: ThyRadioGroup
×
UNCOV
47
        }
×
48
    ],
49
    host: {
UNCOV
50
        '[attr.tabindex]': `-1`
×
51
    },
52
    changeDetection: ChangeDetectionStrategy.OnPush
UNCOV
53
})
×
54
export class ThyRadioGroup implements IThyRadioGroupComponent, ControlValueAccessor, OnInit, OnChanges, AfterContentInit {
55
    private changeDetectorRef = inject(ChangeDetectorRef);
UNCOV
56

×
57
    @HostBinding('class.thy-radio-group') thyRadioGroup = true;
58

UNCOV
59
    @HostBinding('class.btn-group') isButtonGroup = false;
×
UNCOV
60

×
61
    @HostBinding('class.btn-group-outline-default')
62
    isButtonGroupOutline = false;
63

UNCOV
64
    /**
×
UNCOV
65
     * 大小
×
UNCOV
66
     * @type sm | md | lg
×
67
     * @default md
68
     */
69
    readonly thySize = input<string>('md');
UNCOV
70

×
71
    /**
72
     * 布局
UNCOV
73
     * @type flex
×
UNCOV
74
     */
×
UNCOV
75
    readonly thyLayout = input<string>();
×
76

77
    _innerValue: string | number;
78

UNCOV
79
    radios: Array<ThyRadio | ThyRadioButton> = [];
×
80

81
    private hostRenderer = useHostRenderer();
UNCOV
82

×
UNCOV
83
    /**
×
UNCOV
84
     * 是否禁用单选组合框
×
UNCOV
85
     * @default false
×
86
     */
UNCOV
87
    readonly thyDisabled = input(false, { transform: coerceBooleanProperty });
×
UNCOV
88

×
89
    onChange: (_: string) => void = () => null;
×
90
    onTouched: () => void = () => null;
UNCOV
91

×
92
    addRadio(radio: ThyRadio | ThyRadioButton): void {
93
        this.radios.push(radio);
1✔
94
        radio.thyChecked = radio.thyValue() === this._innerValue;
95
    }
96

97
    updateValue(value: string, emit: boolean): void {
98
        this._innerValue = value;
99
        this.radios.forEach(radio => {
100
            radio.thyChecked = radio.thyValue() === this._innerValue;
101
        });
102
        if (emit) {
1✔
103
            this.onChange(value);
104
        }
105
        this.onTouched();
106
        this.changeDetectorRef.detectChanges();
107
    }
108

UNCOV
109
    writeValue(value: any): void {
×
110
        this.updateValue(value, false);
111
    }
112

113
    registerOnChange(fn: any): void {
114
        this.onChange = fn;
115
    }
116

117
    registerOnTouched(fn: any): void {
118
        this.onTouched = fn;
119
    }
120

121
    setDisabledState?(isDisabled: boolean): void {
122
        this.radios.forEach(radio => {
123
            radio.setDisabledState(isDisabled);
124
        });
125
    }
126

127
    setGroup(): void {
128
        if (!this.isButtonGroup && !this.isButtonGroupOutline) {
129
            this.isButtonGroup = true;
130
            this.isButtonGroupOutline = true;
131
        }
132
    }
133

134
    ngOnInit() {
135
        this._setClasses();
136
    }
137

138
    ngOnChanges(changes: SimpleChanges): void {
139
        const { thyDisabled } = changes;
140
        if (thyDisabled) {
141
            this.setDisabledState(this.thyDisabled());
142
        }
143
    }
144

145
    ngAfterContentInit(): void {
146
        this.setDisabledState(this.thyDisabled());
147
    }
148

149
    private _setClasses() {
150
        const classNames: string[] = [];
151
        const size = this.thySize();
152
        if (size && buttonGroupSizeMap[size]) {
153
            classNames.push(buttonGroupSizeMap[size]);
154
        }
155
        const layout = this.thyLayout();
156
        if (layout && radioGroupLayoutMap[layout]) {
157
            classNames.push(radioGroupLayoutMap[layout]);
158
        }
159
        this.hostRenderer.updateClass(classNames);
160
    }
161
}
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