fix: color-picker v-model trigger active-change (#7260)

Co-authored-by: xiaochenchen <xiaochen.chen@igg.com>
This commit is contained in:
Xc 2022-04-25 22:59:49 +08:00 committed by GitHub
parent 7affd9a3fd
commit 6f8d8326c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -166,6 +166,8 @@ export default defineComponent({
const svPanel = ref(null)
const alpha = ref(null)
const popper = ref(null)
// active-change is used to prevent modelValue changes from triggering.
let shouldActiveChange = true
// data
const color = reactive(
new Color({
@ -199,6 +201,7 @@ export default defineComponent({
if (!newVal) {
showPanelColor.value = false
} else if (newVal && newVal !== color.value) {
shouldActiveChange = false
color.fromString(newVal)
}
}
@ -207,7 +210,8 @@ export default defineComponent({
() => currentColor.value,
(val) => {
customInput.value = val
emit('active-change', val)
shouldActiveChange && emit('active-change', val)
shouldActiveChange = true
}
)