Fix getter

This commit is contained in:
Jeremiah Hoyet
2021-11-22 19:18:07 -05:00
parent 6eb79aacdb
commit cfa800c1cd

View File

@@ -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(() => {