Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit ed127cb

Browse files
Googlernshahan
authored andcommitted
Make material radio group actually listen to changes to the value model.
Currently changing the model programmatically doesn't reflect on the selected option. PiperOrigin-RevId: 250355312
1 parent 3d2bbb7 commit ed127cb

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

angular_components/lib/material_radio/material_radio_group.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class MaterialRadioGroupComponent
6161
// by focus calls.
6262
_resetTabIndex();
6363
_selected = _selectedRadioComponent?.value;
64-
if (valueSelection != null && _selected != null) {
65-
valueSelection.select(_selected);
64+
if (_valueSelection != null && _selected != null) {
65+
_valueSelection.select(_selected);
6666
}
6767
_onChange.add(_selected);
6868
}));
@@ -141,7 +141,19 @@ class MaterialRadioGroupComponent
141141

142142
/// Selection model containing value object.
143143
@Input('selectionModel')
144-
SelectionModel valueSelection;
144+
set valueSelection(SelectionModel value) {
145+
if (_valueSelection == value) return;
146+
_selectionSubscription?.cancel();
147+
_valueSelection = value;
148+
_selectionSubscription = _valueSelection?.selectionChanges?.listen((_) {
149+
selected = _valueSelection.selectedValues
150+
.firstWhere((_) => true, orElse: () => null);
151+
});
152+
}
153+
154+
SelectionModel _valueSelection;
155+
StreamSubscription<List<SelectionChangeRecord<dynamic>>>
156+
_selectionSubscription;
145157

146158
/// Internal selection model containing the radio component.
147159
final componentSelection = SelectionModel<MaterialRadioComponent>.single();
@@ -225,5 +237,6 @@ class MaterialRadioGroupComponent
225237
@override
226238
void ngOnDestroy() {
227239
_disposer.dispose();
240+
_selectionSubscription?.cancel();
228241
}
229242
}

0 commit comments

Comments
 (0)