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

atinc / ngx-tethys / d9ae709b-3c27-4b69-b125-b8b80b54f90b

pending completion
d9ae709b-3c27-4b69-b125-b8b80b54f90b

Pull #2757

circleci

mengshuicmq
fix: fix code review
Pull Request #2757: feat(color-picker): color-picker support disabled (#INFR-8645)

98 of 6315 branches covered (1.55%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

2392 of 13661 relevant lines covered (17.51%)

83.12 hits per line

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

13.21
/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
 */
×
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
        }
×
31
    ],
×
32
    changeDetection: ChangeDetectionStrategy.OnPush,
×
33
    standalone: true
×
34
})
×
35
export class ThyRadioGroupComponent implements ControlValueAccessor, OnInit {
×
36
    @HostBinding('class.thy-radio-group') thyRadioGroup = true;
×
37

×
38
    @HostBinding('class.btn-group') isButtonGroup = false;
39

40
    @HostBinding('class.btn-group-outline-default')
×
41
    isButtonGroupOutline = false;
×
42

43
    private _size: string;
44

×
45
    private _layout: string;
×
46

×
47
    /**
48
     * 大小
×
49
     * @type sm | md | lg
×
50
     * @default md
51
     */
×
52
    @Input()
×
53
    set thySize(size: string) {
54
        this._size = size;
55
    }
×
56

57
    @Input()
58
    set thyLayout(layout: string) {
×
59
        this._layout = layout;
60
    }
61

×
62
    _innerValue: string | number;
63

64
    radios: Array<ThyRadioComponent | ThyRadioButtonComponent> = [];
×
65

×
66
    private hostRenderer = useHostRenderer();
67

68
    /**
69
     * 是否禁用单选组合框
×
70
     * @default false
×
71
     */
×
72
    @Input()
73
    @InputBoolean()
74
    set thyDisabled(value: boolean) {
75
        this.setDisabledState(value);
×
76
    }
77

78
    onChange: (_: string) => void = () => null;
×
79
    onTouched: () => void = () => null;
×
80

×
81
    constructor(private changeDetectorRef: ChangeDetectorRef) {}
82

×
83
    addRadio(radio: ThyRadioComponent | ThyRadioButtonComponent): void {
×
84
        this.radios.push(radio);
85
        radio.thyChecked = radio.thyValue === this._innerValue;
×
86
    }
87

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

1✔
100
    writeValue(value: any): void {
101
        this.updateValue(value, false);
102
    }
103

104
    registerOnChange(fn: any): void {
1✔
105
        this.onChange = fn;
106
    }
107

108
    registerOnTouched(fn: any): void {
109
        this.onTouched = fn;
110
    }
111

×
112
    setDisabledState?(isDisabled: boolean): void {
113
        this.radios.forEach(radio => {
114
            radio.setDisabledState(isDisabled);
115
        });
116
    }
117

118
    setGroup() {
119
        if (!this.isButtonGroup && !this.isButtonGroupOutline) {
120
            this.isButtonGroup = true;
121
            this.isButtonGroupOutline = true;
122
        }
123
    }
124

125
    ngOnInit() {
126
        this._setClasses();
127
    }
128

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