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

atinc / ngx-tethys / 4209e40d-4a53-48f5-b396-81cec1d9cc0f

15 Apr 2025 10:18AM UTC coverage: 90.175% (+0.001%) from 90.174%
4209e40d-4a53-48f5-b396-81cec1d9cc0f

push

circleci

minlovehua
feat: demo

5591 of 6865 branches covered (81.44%)

Branch coverage included in aggregate %.

76 of 80 new or added lines in 36 files covered. (95.0%)

67 existing lines in 12 files now uncovered.

13353 of 14143 relevant lines covered (94.41%)

991.7 hits per line

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

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

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

21
const buttonGroupSizeMap = {
7✔
22
    sm: ['btn-group-sm'],
7✔
23
    lg: ['btn-group-lg']
7✔
24
};
7✔
25

7✔
26
const radioGroupLayoutMap = {
7✔
27
    flex: ['radio-group-layout-flex']
7✔
28
};
7✔
29

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

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

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

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

27✔
64
    private _size: string;
65

66
    private _layout: string;
67

7!
68
    /**
7✔
69
     * 大小
7✔
70
     * @type sm | md | lg
71
     * @default md
72
     */
73
    @Input()
10✔
74
    set thySize(size: string) {
75
        this._size = size;
76
    }
12✔
77

12✔
78
    @Input()
9✔
79
    set thyLayout(layout: string) {
80
        this._layout = layout;
81
    }
82

7✔
83
    _innerValue: string | number;
84

85
    radios: Array<IThyRadioComponent | ThyRadioButton> = [];
10✔
86

10✔
87
    private hostRenderer = useHostRenderer();
2✔
88

89
    /**
10!
UNCOV
90
     * 是否禁用单选组合框
×
91
     * @default false
92
     */
10✔
93
    @Input({ transform: coerceBooleanProperty }) thyDisabled = false;
94

1✔
95
    onChange: (_: string) => void = () => null;
96
    onTouched: () => void = () => null;
97

98
    addRadio(radio: IThyRadioComponent | ThyRadioButton): void {
99
        this.radios.push(radio);
100
        radio.thyChecked = radio.thyValue === this._innerValue;
101
    }
102

103
    updateValue(value: string, emit: boolean): void {
1✔
104
        this._innerValue = value;
105
        this.radios.forEach(radio => {
106
            radio.thyChecked = radio.thyValue === this._innerValue;
107
        });
108
        if (emit) {
109
            this.onChange(value);
110
        }
7✔
111
        this.onTouched();
112
        this.changeDetectorRef.detectChanges();
113
    }
114

115
    writeValue(value: any): void {
116
        this.updateValue(value, false);
117
    }
118

119
    registerOnChange(fn: any): void {
120
        this.onChange = fn;
121
    }
122

123
    registerOnTouched(fn: any): void {
124
        this.onTouched = fn;
125
    }
126

127
    setDisabledState?(isDisabled: boolean): void {
128
        this.radios.forEach(radio => {
129
            radio.setDisabledState(isDisabled);
130
        });
131
    }
132

133
    setGroup(): void {
134
        if (!this.isButtonGroup && !this.isButtonGroupOutline) {
135
            this.isButtonGroup = true;
136
            this.isButtonGroupOutline = true;
137
        }
138
    }
139

140
    ngOnInit() {
141
        this._setClasses();
142
    }
143

144
    ngOnChanges(changes: SimpleChanges): void {
145
        const { thyDisabled } = changes;
146
        if (thyDisabled) {
147
            this.setDisabledState(this.thyDisabled);
148
        }
149
    }
150

151
    ngAfterContentInit(): void {
152
        this.setDisabledState(this.thyDisabled);
153
    }
154

155
    private _setClasses() {
156
        const classNames: string[] = [];
157
        if (buttonGroupSizeMap[this._size]) {
158
            classNames.push(buttonGroupSizeMap[this._size]);
159
        }
160
        if (radioGroupLayoutMap[this._layout]) {
161
            classNames.push(radioGroupLayoutMap[this._layout]);
162
        }
163
        this.hostRenderer.updateClass(classNames);
164
    }
165
}
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