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

atinc / ngx-tethys / 881c8997-29c3-4d01-9ef1-22092f16cec2

03 Apr 2024 03:31AM UTC coverage: 90.404% (-0.2%) from 90.585%
881c8997-29c3-4d01-9ef1-22092f16cec2

Pull #3062

circleci

minlovehua
refactor(all): use the transform attribute of @input() instead of @InputBoolean() and @InputNumber()
Pull Request #3062: refactor(all): use the transform attribute of @input() instead of @InputBoolean() and @InputNumber()

5411 of 6635 branches covered (81.55%)

Branch coverage included in aggregate %.

217 of 223 new or added lines in 82 files covered. (97.31%)

201 existing lines in 53 files now uncovered.

13176 of 13925 relevant lines covered (94.62%)

980.1 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
    booleanAttribute,
4
    ChangeDetectionStrategy,
5
    ChangeDetectorRef,
6
    Component,
1✔
7
    forwardRef,
8
    HostBinding,
9
    Input,
10
    OnChanges,
1✔
11
    OnInit,
12
    SimpleChanges
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';
1✔
18
import { ThyRadio } from '../radio.component';
19

10✔
20
const buttonGroupSizeMap = {
21
    sm: ['btn-group-sm'],
UNCOV
22
    lg: ['btn-group-lg']
×
23
};
24

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

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

52
    @HostBinding('class.btn-group') isButtonGroup = false;
53

7✔
54
    @HostBinding('class.btn-group-outline-default')
55
    isButtonGroupOutline = false;
56

7✔
57
    private _size: string;
58

59
    private _layout: string;
23✔
60

27✔
61
    /**
62
     * 大小
63
     * @type sm | md | lg
64
     * @default md
7!
65
     */
7✔
66
    @Input()
7✔
67
    set thySize(size: string) {
68
        this._size = size;
69
    }
70

10✔
71
    @Input()
72
    set thyLayout(layout: string) {
73
        this._layout = layout;
12✔
74
    }
12✔
75

9✔
76
    _innerValue: string | number;
77

78
    radios: Array<ThyRadio | ThyRadioButton> = [];
79

7✔
80
    private hostRenderer = useHostRenderer();
81

82
    /**
10✔
83
     * 是否禁用单选组合框
10✔
84
     * @default false
2✔
85
     */
86
    @Input({ transform: booleanAttribute }) thyDisabled: boolean;
10!
UNCOV
87

×
88
    onChange: (_: string) => void = () => null;
89
    onTouched: () => void = () => null;
10✔
90

91
    constructor(private changeDetectorRef: ChangeDetectorRef) {}
1✔
92

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

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

110
    writeValue(value: any): void {
7✔
111
        this.updateValue(value, false);
112
    }
113

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

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

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

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

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

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

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

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