Skip to content

Commit 34e9332

Browse files
refactor(components/forms)!: update checked and radioType input types (#742)
1 parent f2f4ad3 commit 34e9332

File tree

6 files changed

+24
-28
lines changed

6 files changed

+24
-28
lines changed

libs/components/forms/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export * from './lib/modules/input-box/input-box-host.service';
1717
export * from './lib/modules/input-box/input-box-populate-args';
1818

1919
export * from './lib/modules/radio/types/radio-change';
20+
export * from './lib/modules/radio/types/radio-type';
2021
export * from './lib/modules/radio/radio.module';
2122

2223
export * from './lib/modules/selection-box/types/selection-box-grid-align-items';
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Component } from '@angular/core';
22

3+
import { SkyRadioType } from '../types/radio-type';
4+
35
@Component({
46
templateUrl: './radio-single.component.fixture.html',
57
})
68
export class SkySingleRadioComponent {
79
public icon = 'bold';
8-
public radioType: string | undefined;
10+
public radioType: SkyRadioType | undefined;
911
}

libs/components/forms/src/lib/modules/radio/radio-group.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export class SkyRadioGroupComponent
220220
}
221221
}
222222

223-
public watchForSelections() {
223+
public watchForSelections(): void {
224224
/* istanbul ignore else */
225225
if (this.radios) {
226226
this.radios.forEach((radio) => {
@@ -238,7 +238,7 @@ export class SkyRadioGroupComponent
238238
}
239239
}
240240

241-
public ngOnDestroy() {
241+
public ngOnDestroy(): void {
242242
this.#ngUnsubscribe.next();
243243
this.#ngUnsubscribe.complete();
244244
}
@@ -257,7 +257,7 @@ export class SkyRadioGroupComponent
257257
* @internal
258258
* Indicates whether to disable the control. Implemented as a part of ControlValueAccessor.
259259
*/
260-
public setDisabledState(isDisabled: boolean) {
260+
public setDisabledState(isDisabled: boolean): void {
261261
this.disabled = isDisabled;
262262
}
263263

libs/components/forms/src/lib/modules/radio/radio.component.spec.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import { SkyRadioLabelComponent } from './radio-label.component';
1818
import { SkyRadioComponent } from './radio.component';
1919

2020
describe('Radio component', function () {
21-
let fixture: ComponentFixture<any>;
22-
let componentInstance: any;
23-
2421
beforeEach(function () {
2522
TestBed.configureTestingModule({
2623
imports: [SkyRadioFixturesModule],
@@ -32,35 +29,29 @@ describe('Radio component', function () {
3229
spyOn(idSvc, 'generateId').and.callFake(() => `MOCK_ID_${++uniqueId}`);
3330
});
3431

35-
afterEach(function () {
36-
if (fixture) {
37-
fixture.destroy();
38-
}
39-
});
40-
4132
describe('Standard radio component', () => {
42-
let testComponent: SkyRadioTestComponent;
33+
let fixture: ComponentFixture<SkyRadioTestComponent>;
34+
let componentInstance: SkyRadioTestComponent;
4335

4436
beforeEach(fakeAsync(() => {
4537
fixture = TestBed.createComponent(SkyRadioTestComponent);
4638

4739
componentInstance = fixture.componentInstance;
48-
testComponent = fixture.debugElement.componentInstance;
4940

5041
fixture.detectChanges();
5142
tick();
5243
}));
5344

5445
it('should emit the new disabled value when it is modified', () => {
55-
const onDisabledChangeSpy = spyOn(testComponent, 'onDisabledChange');
46+
const onDisabledChangeSpy = spyOn(componentInstance, 'onDisabledChange');
5647
expect(onDisabledChangeSpy).toHaveBeenCalledTimes(0);
57-
testComponent.disabled1 = true;
48+
componentInstance.disabled1 = true;
5849
fixture.detectChanges();
5950
expect(onDisabledChangeSpy).toHaveBeenCalledTimes(1);
6051
});
6152

6253
it('should emit when radio is checked', async () => {
63-
const onCheckedChangeSpy = spyOn(testComponent, 'onCheckedChange');
54+
const onCheckedChangeSpy = spyOn(componentInstance, 'onCheckedChange');
6455
const radios: NodeListOf<HTMLInputElement> =
6556
fixture.nativeElement.querySelectorAll('input');
6657

@@ -224,7 +215,7 @@ describe('Radio component', function () {
224215
}));
225216

226217
it('should pass a tabindex when specified', fakeAsync(function () {
227-
componentInstance.tabindex2 = '3';
218+
componentInstance.tabindex2 = 3;
228219
fixture.detectChanges();
229220
tick();
230221

@@ -286,6 +277,7 @@ describe('Radio component', function () {
286277

287278
describe('Radio icon component', () => {
288279
let debugElement: DebugElement;
280+
let fixture: ComponentFixture<SkySingleRadioComponent>;
289281

290282
beforeEach(() => {
291283
fixture = TestBed.createComponent(SkySingleRadioComponent);
@@ -344,6 +336,9 @@ describe('Radio component', function () {
344336
});
345337

346338
describe('Radio component with a consumer using OnPush change detection', () => {
339+
let fixture: ComponentFixture<SkyRadioOnPushTestComponent>;
340+
let componentInstance: SkyRadioOnPushTestComponent;
341+
347342
beforeEach(function () {
348343
fixture = TestBed.createComponent(SkyRadioOnPushTestComponent);
349344

libs/components/forms/src/lib/modules/radio/radio.component.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { SkyFormsUtility } from '../shared/forms-utility';
1919

2020
import { SkyRadioGroupIdService } from './radio-group-id.service';
2121
import { SkyRadioChange } from './types/radio-change';
22+
import { SkyRadioType } from './types/radio-type';
2223

2324
/**
2425
* Provider Expression that allows sky-radio to register as a ControlValueAccessor.
@@ -53,7 +54,7 @@ export class SkyRadioComponent implements OnDestroy, ControlValueAccessor {
5354
* @default false
5455
*/
5556
@Input()
56-
public set checked(value: boolean) {
57+
public set checked(value: boolean | undefined) {
5758
const newCheckedState = !!value;
5859

5960
if (this.#_checked !== newCheckedState) {
@@ -214,15 +215,11 @@ export class SkyRadioComponent implements OnDestroy, ControlValueAccessor {
214215
* @default "info"
215216
*/
216217
@Input()
217-
public get radioType(): string {
218+
public get radioType(): SkyRadioType {
218219
return this.#_radioType;
219220
}
220-
public set radioType(value: string | undefined) {
221-
if (value) {
222-
this.#_radioType = value.toLocaleLowerCase();
223-
} else {
224-
this.#_radioType = 'info';
225-
}
221+
public set radioType(value: SkyRadioType | undefined) {
222+
this.#_radioType = value ?? 'info';
226223
}
227224

228225
/**
@@ -262,7 +259,7 @@ export class SkyRadioComponent implements OnDestroy, ControlValueAccessor {
262259
#_checked = false;
263260
#_disabled = false;
264261
#_name: string | undefined;
265-
#_radioType = 'info';
262+
#_radioType: SkyRadioType = 'info';
266263
#_selectedValue: unknown;
267264
#_tabindex = 0;
268265
#_value: any;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type SkyRadioType = 'danger' | 'info' | 'success' | 'warning';

0 commit comments

Comments
 (0)