tp-radio-group/tp-radio-group.js

39 lines
685 B
JavaScript
Raw Permalink Normal View History

2022-04-29 20:32:47 +02:00
/**
@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);