From 3ef39cbe8d28ceb0dd7296eff5b0d11d66834bbc Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 21 Nov 2017 13:00:08 -0600 Subject: [PATCH] fix(radio): set initial radio-group value --- .../src/components/radio-group/radio-group.tsx | 17 +++++++++++++++-- .../components/radio-group/test/form/index.html | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/core/src/components/radio-group/radio-group.tsx b/packages/core/src/components/radio-group/radio-group.tsx index 3e36f31714..5ecf276fbb 100644 --- a/packages/core/src/components/radio-group/radio-group.tsx +++ b/packages/core/src/components/radio-group/radio-group.tsx @@ -87,9 +87,22 @@ export class RadioGroup implements ComponentDidLoad, RadioGroupInput { this.radios.push(radio); radio.name = this.name; - if (radio.checked && !this.value) { - // set the initial value from the check radio's value + if (this.value !== undefined && radio.value === this.value) { + // this radio-group has a value and this + // radio equals the correct radio-group value + // so let's check this radio + radio.checked = true; + + } else if (this.value === undefined && radio.checked) { + // this radio-group does not have a value + // but this radio is checked, so let's set the + // radio-group's value from the checked radio this.value = radio.value; + + } else if (radio.checked) { + // if it doesn't match one of the above cases, but the + // radio is still checked, then we need to uncheck it + radio.checked = false; } } diff --git a/packages/core/src/components/radio-group/test/form/index.html b/packages/core/src/components/radio-group/test/form/index.html index 9e2cb9a45e..451f486178 100644 --- a/packages/core/src/components/radio-group/test/form/index.html +++ b/packages/core/src/components/radio-group/test/form/index.html @@ -21,7 +21,7 @@ - + Luckiest Man On Earth