Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Fixed radio buttons permanently being checked when outside of a group #1982

Merged
merged 2 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/modules/radio/radio.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ describe('Radio component', function () {
expect(ngModel.valid).toBe(true);
expect(ngModel.pristine).toBe(false);
expect(ngModel.touched).toBe(true);
expect(radios.item(1).checked).toBe(true);
expect(radios.item(0).checked).toBeFalsy();
expect(radios.item(1).checked).toBeTruthy();
expect(radios.item(2).checked).toBeFalsy();
expect(componentInstance.selectedValue).toBe('2');

SkyAppTestUtility.fireDomEvent(radios.item(1), 'blur');
Expand Down Expand Up @@ -106,7 +108,9 @@ describe('Radio component', function () {
tick();

const radios = fixture.nativeElement.querySelectorAll('input');
expect(radios.item(1).checked).toBe(true);
expect(radios.item(0).checked).toBeFalsy();
expect(radios.item(1).checked).toBeTruthy();
expect(radios.item(2).checked).toBeFalsy();
}));

it('should maintain checked state when value is changed', fakeAsync(function() {
Expand All @@ -122,6 +126,8 @@ describe('Radio component', function () {

radios = fixture.nativeElement.querySelectorAll('input');
expect(radios.item(0).checked).toBeTruthy();
expect(radios.item(1).checked).toBeFalsy();
expect(radios.item(2).checked).toBeFalsy();
}));

it('should handle disabled state properly', fakeAsync(function () {
Expand All @@ -134,7 +140,9 @@ describe('Radio component', function () {
fixture.detectChanges();
tick();

expect(radios.item(1).checked).toBe(false);
expect(radios.item(0).checked).toBeTruthy();
expect(radios.item(1).checked).toBeFalsy();
expect(radios.item(2).checked).toBeFalsy();
expect(componentInstance.selectedValue).toBe('1');

componentInstance.disabled2 = false;
Expand All @@ -145,7 +153,9 @@ describe('Radio component', function () {
fixture.detectChanges();
tick();

expect(radios.item(1).checked).toBe(true);
expect(radios.item(0).checked).toBeFalsy();
expect(radios.item(1).checked).toBeTruthy();
expect(radios.item(2).checked).toBeFalsy();
expect(componentInstance.selectedValue).toBe('2');
}));

Expand Down
7 changes: 1 addition & 6 deletions src/modules/radio/radio.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export class SkyRadioComponent implements OnDestroy, ControlValueAccessor {
public get change(): Observable<SkyRadioChange> {
return this._change;
}

public get inputId(): string {
return `sky-radio-${this.id}-input`;
}
Expand All @@ -142,7 +141,6 @@ export class SkyRadioComponent implements OnDestroy, ControlValueAccessor {
this._selectedValue = value;
}
}

public get selectedValue(): any {
return this._selectedValue;
}
Expand All @@ -168,10 +166,7 @@ export class SkyRadioComponent implements OnDestroy, ControlValueAccessor {
}

this.selectedValue = value;

if (this.value === this.selectedValue) {
this.checked = true;
}
this.checked = this.value === this.selectedValue;

this.changeDetector.markForCheck();
}
Expand Down