Skip to content

Commit 37ec7e9

Browse files
authored
fix(b-form-checkbox/b-form-radio): chnage event timing (#6008)
1 parent afdd540 commit 37ec7e9

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/components/form-checkbox/form-checkbox.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,19 @@ export const BFormCheckbox = /*#__PURE__*/ Vue.extend({
102102
}
103103
this.computedLocalChecked = localChecked
104104

105-
// Change is only emitted on user interaction
106-
this.$emit('change', localChecked)
105+
// Fire events in a `$nextTick()` to ensure the `v-model` is updated
106+
this.$nextTick(() => {
107+
// Change is only emitted on user interaction
108+
this.$emit('change', localChecked)
107109

108-
// If this is a child of `<form-checkbox-group>`,
109-
// we emit a change event on it as well
110-
if (this.isGroup) {
111-
this.bvGroup.$emit('change', localChecked)
112-
}
110+
// If this is a child of `<form-checkbox-group>`,
111+
// we emit a change event on it as well
112+
if (this.isGroup) {
113+
this.bvGroup.$emit('change', localChecked)
114+
}
113115

114-
this.$emit('update:indeterminate', indeterminate)
116+
this.$emit('update:indeterminate', indeterminate)
117+
})
115118
},
116119
setIndeterminate(state) {
117120
// Indeterminate only supported in single checkbox mode

src/components/form-radio/form-radio.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ export const BFormRadio = /*#__PURE__*/ Vue.extend({
3131
}
3232
},
3333
computed: {
34-
// Radio Groups can only have a single value, so determining if checked is simple
3534
isChecked() {
3635
return looseEqual(this.value, this.computedLocalChecked)
3736
},
38-
// Flags for form-radio-check mixin
3937
isRadio() {
4038
return true
4139
},
@@ -44,21 +42,30 @@ export const BFormRadio = /*#__PURE__*/ Vue.extend({
4442
}
4543
},
4644
watch: {
47-
// Radio Groups can only have a single value, so our watchers are simple
48-
computedLocalChecked() {
49-
this.$emit('input', this.computedLocalChecked)
45+
computedLocalChecked(newValue, oldValue) {
46+
if (!looseEqual(newValue, oldValue)) {
47+
this.$emit('input', newValue)
48+
}
5049
}
5150
},
5251
methods: {
5352
handleChange({ target: { checked } }) {
54-
const value = this.value
53+
const { value } = this
54+
const localChecked = checked ? value : null
55+
5556
this.computedLocalChecked = value
56-
// Change is only emitted on user interaction
57-
this.$emit('change', checked ? value : null)
58-
// If this is a child of form-radio-group, we emit a change event on it as well
59-
if (this.isGroup) {
60-
this.bvGroup.$emit('change', checked ? value : null)
61-
}
57+
58+
// Fire events in a `$nextTick()` to ensure the `v-model` is updated
59+
this.$nextTick(() => {
60+
// Change is only emitted on user interaction
61+
this.$emit('change', localChecked)
62+
63+
// If this is a child of `<form-radio-group>`,
64+
// we emit a change event on it as well
65+
if (this.isGroup) {
66+
this.bvGroup.$emit('change', localChecked)
67+
}
68+
})
6269
}
6370
}
6471
})

0 commit comments

Comments
 (0)