Skip to content

Commit 4e48cf4

Browse files
tinayuangaommalerba
authored andcommitted
fix(radio): radios aren't checkable when the value is falsy (#10315)
1 parent c367e66 commit 4e48cf4

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/lib/radio/radio.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class MatRadioGroup extends _MatRadioGroupMixinBase
155155
@Input()
156156
get value(): any { return this._value; }
157157
set value(newValue: any) {
158-
if (this._value != newValue) {
158+
if (this._value !== newValue) {
159159
// Set this before proceeding to ensure no circular loop occurs with selection.
160160
this._value = newValue;
161161

@@ -231,12 +231,12 @@ export class MatRadioGroup extends _MatRadioGroupMixinBase
231231
/** Updates the `selected` radio button from the internal _value state. */
232232
private _updateSelectedRadioFromValue(): void {
233233
// If the value already matches the selected radio, do nothing.
234-
const isAlreadySelected = this._selected != null && this._selected.value == this._value;
234+
const isAlreadySelected = this._selected !== null && this._selected.value === this._value;
235235

236-
if (this._radios != null && !isAlreadySelected) {
236+
if (this._radios && !isAlreadySelected) {
237237
this._selected = null;
238238
this._radios.forEach(radio => {
239-
radio.checked = this.value == radio.value;
239+
radio.checked = this.value === radio.value;
240240
if (radio.checked) {
241241
this._selected = radio;
242242
}
@@ -357,13 +357,12 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
357357
get checked(): boolean { return this._checked; }
358358
set checked(value: boolean) {
359359
const newCheckedState = coerceBooleanProperty(value);
360-
361-
if (this._checked != newCheckedState) {
360+
if (this._checked !== newCheckedState) {
362361
this._checked = newCheckedState;
363-
364-
if (newCheckedState && this.radioGroup && this.radioGroup.value != this.value) {
362+
if (newCheckedState && this.radioGroup && this.radioGroup.value !== this.value) {
365363
this.radioGroup.selected = this;
366-
} else if (!newCheckedState && this.radioGroup && this.radioGroup.value == this.value) {
364+
} else if (!newCheckedState && this.radioGroup && this.radioGroup.value === this.value) {
365+
367366
// When unchecking the selected radio button, update the selected radio
368367
// property on the group.
369368
this.radioGroup.selected = null;
@@ -381,12 +380,12 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
381380
@Input()
382381
get value(): any { return this._value; }
383382
set value(value: any) {
384-
if (this._value != value) {
383+
if (this._value !== value) {
385384
this._value = value;
386-
if (this.radioGroup != null) {
385+
if (this.radioGroup !== null) {
387386
if (!this.checked) {
388387
// Update checked when the value changed to match the radio group's value
389-
this.checked = this.radioGroup.value == value;
388+
this.checked = this.radioGroup.value === value;
390389
}
391390
if (this.checked) {
392391
this.radioGroup.selected = this;
@@ -408,7 +407,7 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
408407
/** Whether the radio button is disabled. */
409408
@Input()
410409
get disabled(): boolean {
411-
return this._disabled || (this.radioGroup != null && this.radioGroup.disabled);
410+
return this._disabled || (this.radioGroup !== null && this.radioGroup.disabled);
412411
}
413412
set disabled(value: boolean) {
414413
this._disabled = coerceBooleanProperty(value);
@@ -473,7 +472,7 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
473472

474473
this._removeUniqueSelectionListener =
475474
_radioDispatcher.listen((id: string, name: string) => {
476-
if (id != this.id && name == this.name) {
475+
if (id !== this.id && name === this.name) {
477476
this.checked = false;
478477
}
479478
});
@@ -545,7 +544,7 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
545544
// emit its event object to the `change` output.
546545
event.stopPropagation();
547546

548-
const groupValueChanged = this.radioGroup && this.value != this.radioGroup.value;
547+
const groupValueChanged = this.radioGroup && this.value !== this.radioGroup.value;
549548
this.checked = true;
550549
this._emitChangeEvent();
551550

0 commit comments

Comments
 (0)