lion/packages/radio-group/src/LionRadioGroup.js

35 lines
1,023 B
JavaScript

import { LitElement } from '@lion/core';
import { ChoiceGroupMixin, FormGroupMixin } from '@lion/form-core';
/**
* A wrapper around multiple radios.
*/
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/40110
export class LionRadioGroup extends ChoiceGroupMixin(FormGroupMixin(LitElement)) {
connectedCallback() {
super.connectedCallback();
this.setAttribute('role', 'radiogroup');
}
/**
* @override FormGroupMixin, during a reset if the current checked value is behind
* the initial checked value, they both got unchecked
*/
resetGroup() {
let initValue;
this.formElements.forEach(child => {
if (typeof child.resetGroup === 'function') {
child.resetGroup();
} else if (typeof child.reset === 'function') {
child.reset();
// If the value was initially checked save this
if (child.checked) {
initValue = child.value;
}
}
});
this.modelValue = initValue;
this.resetInteractionState();
}
}