mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
Fix getter
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user