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

atinc / ngx-tethys / 72d4a45b-d882-47cc-8e26-20c206ba0752

08 Nov 2023 06:11AM UTC coverage: 90.182% (+0.02%) from 90.166%
72d4a45b-d882-47cc-8e26-20c206ba0752

Pull #2887

circleci

smile1016
fix(cascader): fix trigger area and style #INFR-10245
Pull Request #2887: fix(cascader): fix trigger area and style #INFR-10245

5224 of 6459 branches covered (0.0%)

Branch coverage included in aggregate %.

13137 of 13901 relevant lines covered (94.5%)

978.76 hits per line

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

89.83
/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
} from '@angular/core';
1✔
13
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
14
import { useHostRenderer } from '@tethys/cdk/dom';
15
import { InputBoolean } from 'ngx-tethys/core';
16

17
import { ThyRadioButtonComponent } from '../button/radio-button.component';
18
import { ThyRadioComponent } from '../radio.component';
19

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

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

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

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

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

57
    private _size: string;
58

7✔
59
    private _layout: string;
60

61
    private _disabled: boolean;
7✔
62

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

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

78
    _innerValue: string | number;
12✔
79

12✔
80
    radios: Array<ThyRadioComponent | ThyRadioButtonComponent> = [];
9✔
81

82
    private hostRenderer = useHostRenderer();
83

84
    /**
7✔
85
     * 是否禁用单选组合框
86
     * @default false
87
     */
10✔
88
    @Input()
10✔
89
    @InputBoolean()
2✔
90
    set thyDisabled(value: boolean) {
91
        this._disabled = value;
10!
92
    }
×
93

94
    onChange: (_: string) => void = () => null;
10✔
95
    onTouched: () => void = () => null;
96

1✔
97
    constructor(private changeDetectorRef: ChangeDetectorRef) {}
98

99
    addRadio(radio: ThyRadioComponent | ThyRadioButtonComponent): void {
1✔
100
        this.radios.push(radio);
101
        radio.thyChecked = radio.thyValue === this._innerValue;
102
    }
103

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

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

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

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

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

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

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

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

152
    ngAfterContentInit(): void {
153
        this.setDisabledState(this._disabled);
154
    }
155

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