优化多选框

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

View File

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