39 lines
685 B
JavaScript
39 lines
685 B
JavaScript
|
/**
|
||
|
@license
|
||
|
Copyright (c) 2022 trading_peter
|
||
|
This program is available under Apache License Version 2.0
|
||
|
*/
|
||
|
|
||
|
import { LitElement, html, css } from 'lit';
|
||
|
|
||
|
class TpRadioGroup extends LitElement {
|
||
|
static get styles() {
|
||
|
return [
|
||
|
css`
|
||
|
:host {
|
||
|
display: block;
|
||
|
}
|
||
|
`
|
||
|
];
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
return html`
|
||
|
<slot @checked=${this.updateValue}></slot>
|
||
|
`;
|
||
|
}
|
||
|
|
||
|
updateValue(e) {
|
||
|
const target = e.target;
|
||
|
const radios = this.querySelectorAll('tp-radio');
|
||
|
|
||
|
radios.forEach(radio => {
|
||
|
if (radio !== target) {
|
||
|
radio.checked = false;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.customElements.define('tp-radio-group', TpRadioGroup);
|