Skip to content

Commit

Permalink
fix(runtime-web): 页面存在多个 checkbox 时无法独立使用
Browse files Browse the repository at this point in the history
  • Loading branch information
hwaphon committed Jan 16, 2024
1 parent c4850ed commit ac263c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/runtime-web/src/components/src/form/checkbox-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export default class CheckboxGroup
disconnectedCallback() {
super.disconnectedCallback()

window.removeEventListener(
this.removeEventListener(
'call-tiga-checkbox-group-event',
this._callTigaCheckboxGroup
)
window.removeEventListener(
this.removeEventListener(
'init-tiga-checkbox-group-event',
this._initTigaCheckboxGroup
)
Expand Down Expand Up @@ -119,7 +119,7 @@ export default class CheckboxGroup
this.changeValueList(value)
}

_initTigaCheckboxGroup = () => {
_initTigaCheckboxGroup = (e) => {
const nodeList = this.querySelectorAll('tiga-checkbox')
nodeList.forEach((item) => {
const checkbox: any = item
Expand All @@ -133,12 +133,12 @@ export default class CheckboxGroup
}

addListener() {
window.addEventListener(
this.addEventListener(
'call-tiga-checkbox-group-event',
this._callTigaCheckboxGroup
)

window.addEventListener(
this.addEventListener(
'init-tiga-checkbox-group-event',
this._initTigaCheckboxGroup
)
Expand Down
10 changes: 6 additions & 4 deletions packages/runtime-web/src/components/src/form/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ export default class Checkbox extends BaseElement {
connectedCallback() {
super.connectedCallback()
if (this.checked) {
window.dispatchEvent(
this.dispatchEvent(
new CustomEvent('init-tiga-checkbox-group-event', {
detail: {
value: this.value
}
},
bubbles: true
})
)
}
Expand All @@ -91,15 +92,16 @@ export default class Checkbox extends BaseElement {
}

_emitEvent(e) {
window.dispatchEvent(new CustomEvent('call-tiga-checkbox-group-event', e))
this.dispatchEvent(new CustomEvent('call-tiga-checkbox-group-event', e))
}

_handleClick() {
if (!this.disabled) {
this._emitEvent({
detail: {
value: this.value
}
},
bubbles: true
})
}
}
Expand Down

0 comments on commit ac263c4

Please sign in to comment.