优化多选框

master
yutent 2023-11-20 18:57:13 +08:00
parent 0ac39d443f
commit 07901c84fb
2 changed files with 9 additions and 5 deletions

View File

@ -37,6 +37,7 @@ class Checkbox extends Component {
} else { } else {
this.value.push(ev.value) this.value.push(ev.value)
} }
this.$emit('input', { data: this.value })
this.$emit('change', { data: this.value }) this.$emit('change', { data: this.value })
}) })
@ -211,7 +212,7 @@ class CheckboxItem extends Component {
` `
] ]
toggleCheck(ev) { #toggleCheck(ev) {
if (this.disabled || this.readOnly) { if (this.disabled || this.readOnly) {
return return
} }
@ -227,13 +228,14 @@ class CheckboxItem extends Component {
if (this.inGroup) { if (this.inGroup) {
this.parentNode.$emit('child-change', data) this.parentNode.$emit('child-change', data)
} else { } else {
this.$emit('input', data)
this.$emit('change', data) this.$emit('change', data)
} }
} }
handleClick(ev) { #click(ev) {
if (ev.type === 'click' || ev.keyCode === 32) { if (ev.type === 'click' || ev.keyCode === 32) {
this.toggleCheck(ev) this.#toggleCheck(ev)
} }
} }
@ -246,8 +248,8 @@ class CheckboxItem extends Component {
render() { render() {
return html` <label return html` <label
tabindex=${this.disabled || this.readOnly ? 'none' : 0} tabindex=${this.disabled || this.readOnly ? 'none' : 0}
@click=${this.handleClick} @click=${this.#click}
@keydown=${this.handleClick} @keydown=${this.#click}
> >
<span class="dot"><wc-icon name="get"></wc-icon></span> <span class="dot"><wc-icon name="get"></wc-icon></span>
<slot></slot> <slot></slot>

View File

@ -32,6 +32,7 @@ class Radio extends Component {
this.$on('child-change', ev => { this.$on('child-change', ev => {
ev.stopPropagation() ev.stopPropagation()
this.value = ev.value this.value = ev.value
this.$emit('input', { data: ev.value })
this.$emit('change', { data: ev.value }) this.$emit('change', { data: ev.value })
}) })
this.#updateChildrenStat(true) this.#updateChildrenStat(true)
@ -215,6 +216,7 @@ class RadioItem extends Component {
if (this.inGroup) { if (this.inGroup) {
this.parentNode.$emit('child-change', { value: this.value }) this.parentNode.$emit('child-change', { value: this.value })
} else { } else {
this.$emit('input')
this.$emit('change') this.$emit('change')
} }
} }