Skip to content

Commit

Permalink
Merge pull request #151 from hwaphon/fix/web_checkbox
Browse files Browse the repository at this point in the history
fix(runtime-web): 页面存在多个 checkbox 时无法独立使用
  • Loading branch information
hwaphon authored Jan 16, 2024
2 parents c8ad5b4 + ac263c4 commit 61449e3
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 61449e3

Please sign in to comment.