Skip to content

Commit 3e9427b

Browse files
committed
feat(radio): add disabled to radio-group and support disabled formcontrol
fixes #9998
1 parent 0aad835 commit 3e9427b

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

src/components/radio/radio-button.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class RadioButton extends Ion implements IonicTapInput, OnDestroy, OnInit
173173
*/
174174
@Input()
175175
get disabled(): boolean {
176-
return this._disabled;
176+
return this._disabled || (this._group != null && this._group.disabled);
177177
}
178178
set disabled(val: boolean) {
179179
this._disabled = isTrueProperty(val);
@@ -207,6 +207,10 @@ export class RadioButton extends Ion implements IonicTapInput, OnDestroy, OnInit
207207
if (this._group && isPresent(this._group.value)) {
208208
this.checked = isCheckedProperty(this._group.value, this.value);
209209
}
210+
211+
if (this._group && this._group.disabled) {
212+
this.disabled = this._group.disabled;
213+
}
210214
}
211215

212216
/**

src/components/radio/radio-group.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ChangeDetectorRef, ContentChild, Directive, ElementRef, EventEmitter, forwardRef, Output, Renderer } from '@angular/core';
1+
import { ChangeDetectorRef, ContentChild, Directive, ElementRef, EventEmitter, forwardRef, Input, Output, Renderer } from '@angular/core';
22
import { NG_VALUE_ACCESSOR } from '@angular/forms';
33

44
import { ListHeader } from '../list/list-header';
5-
import { isCheckedProperty } from '../../util/util';
5+
import { isCheckedProperty, isTrueProperty } from '../../util/util';
66
import { RadioButton } from './radio-button';
77

88
export const RADIO_VALUE_ACCESSOR: any = {
@@ -71,6 +71,11 @@ export const RADIO_VALUE_ACCESSOR: any = {
7171
})
7272
export class RadioGroup {
7373

74+
/**
75+
* @internal
76+
*/
77+
_disabled: boolean = false;
78+
7479
/**
7580
* @private
7681
*/
@@ -101,6 +106,17 @@ export class RadioGroup {
101106
*/
102107
id: number;
103108

109+
/**
110+
* @input {boolean} Whether all radio buttons in the group should be disabled. Default false.
111+
*/
112+
@Input()
113+
get disabled(): boolean {
114+
return this._disabled;
115+
}
116+
set disabled(val: boolean) {
117+
this._disabled = isTrueProperty(val);
118+
}
119+
104120
/**
105121
* @output {any} expression to be evaluated when selection has been changed
106122
*/
@@ -248,6 +264,13 @@ export class RadioGroup {
248264
*/
249265
onTouched() {}
250266

267+
/**
268+
* @private
269+
*/
270+
setDisabledState(isDisabled: boolean) {
271+
this.disabled = isDisabled;
272+
}
273+
251274
}
252275

253276
let radioGroupIds = -1;

src/components/radio/test/basic/app-module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export class E2EPage {
1818
'fruitsCtrl': this.fruitsCtrl
1919
});
2020

21+
friendsCtrl = new FormControl({value: 'enemies', disabled: true});
22+
friendsForm = new FormGroup({
23+
'friendsCtrl': this.friendsCtrl
24+
});
25+
2126
currenciesControl = new FormControl('EUR');
2227
currencyForm = new FormGroup({
2328
'currenciesControl': this.currenciesControl

src/components/radio/test/basic/main.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,30 @@
142142
</ion-item>
143143
</ion-list>
144144

145+
<ion-list radio-group disabled="true" [(ngModel)]="relationship">
146+
<ion-list-header>Disabled radio-group</ion-list-header>
147+
<ion-item>
148+
<ion-label>Friends</ion-label>
149+
<ion-radio value="friends"></ion-radio>
150+
</ion-item>
151+
<ion-item>
152+
<ion-label>Enemies</ion-label>
153+
<ion-radio value="enemies"></ion-radio>
154+
</ion-item>
155+
</ion-list>
156+
157+
<form [formGroup]="friendsForm">
158+
<ion-list radio-group formControlName="friendsCtrl">
159+
<ion-list-header>Disabled formGroup</ion-list-header>
160+
<ion-item>
161+
<ion-label>Friends</ion-label>
162+
<ion-radio value="friends"></ion-radio>
163+
</ion-item>
164+
<ion-item>
165+
<ion-label>Enemies</ion-label>
166+
<ion-radio value="enemies"></ion-radio>
167+
</ion-item>
168+
</ion-list>
169+
</form>
170+
145171
</ion-content>

0 commit comments

Comments
 (0)