UNPKG

@tarojs/components

Version:
100 lines (99 loc) 2.58 kB
// eslint-disable-next-line @typescript-eslint/no-unused-vars import { Component, h, Host, Prop, Event, Listen, Element } from '@stencil/core'; export class RadioGroup { constructor() { this.uniqueName = Date.now().toString(36); } function(e) { e.stopPropagation(); if (e.target.tagName !== 'TARO-RADIO-CORE') return; const target = e.target; if (target.checked) { const childList = this.el.querySelectorAll('taro-radio-core'); childList.forEach(element => { if (element !== target) { element.checked = false; } }); this.value = e.detail.value; this.onChange.emit({ value: this.value }); } } componentDidLoad() { const childList = this.el.querySelectorAll('taro-radio-core'); childList.forEach((element) => { element.setAttribute('name', this.name || this.uniqueName); }); Object.defineProperty(this.el, 'value', { get: () => { if (!this.value) { const childList = this.el.querySelectorAll('taro-radio-core'); this.value = this.getValues(childList); } return this.value; }, configurable: true }); } getValues(childList) { let val = ''; Array.from(childList) .forEach(element => { const checkbox = element.querySelector('input'); if (checkbox === null || checkbox === void 0 ? void 0 : checkbox.checked) { val = checkbox.value || ''; } }); return val; } render() { return (h(Host, { class: 'weui-cells_radiogroup' })); } static get is() { return "taro-radio-group-core"; } static get properties() { return { "name": { "type": "any", "mutable": false, "complexType": { "original": "any", "resolved": "any", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "name", "reflect": false } }; } static get events() { return [{ "method": "onChange", "name": "change", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "" }, "complexType": { "original": "any", "resolved": "any", "references": {} } }]; } static get elementRef() { return "el"; } static get listeners() { return [{ "name": "radiochange", "method": "function", "target": undefined, "capture": false, "passive": false }]; } }