From cfa800c1cd58242cb5e7005f325402b1fcddbd1c Mon Sep 17 00:00:00 2001 From: Jeremiah Hoyet Date: Mon, 22 Nov 2021 19:18:07 -0500 Subject: [PATCH] Fix getter --- src/components/radio-group/radio-group.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/components/radio-group/radio-group.ts b/src/components/radio-group/radio-group.ts index 3c7389436..dfc5b2826 100644 --- a/src/components/radio-group/radio-group.ts +++ b/src/components/radio-group/radio-group.ts @@ -24,6 +24,14 @@ export default class SlRadioGroup extends LitElement { /** The radio group label. Required for proper accessibility. Alternatively, you can use the label slot. */ @property() label = ''; + /** The current value of the radio group. */ + @property() + get value() { + if (!this._value) return this.getCurrentValue(); + + return this._value; + } + set value(newValue) { const index = this.getAllRadios().findIndex(el => el.value === newValue); const oldValue = this._value; @@ -38,12 +46,6 @@ export default class SlRadioGroup extends LitElement { } } - /** The current value of the radio group. */ - @property() - get value() { - return this._value; - } - /** Shows the fieldset and legend that surrounds the radio group. */ @property({ type: Boolean, attribute: 'fieldset' }) fieldset = false; @@ -66,6 +68,12 @@ export default class SlRadioGroup extends LitElement { }); } + getCurrentValue() { + const valRadio = this.getAllRadios().filter(el => el.checked); + this._value = valRadio.length === 1 ? valRadio[0].value : ''; + return this._value; + } + handleFocusIn() { // When tabbing into the fieldset, make sure it lands on the checked radio requestAnimationFrame(() => {