Skip to content

Commit

Permalink
fix(color-picker): fix v-model not working
Browse files Browse the repository at this point in the history
  • Loading branch information
oljc committed Mar 19, 2024
1 parent faf3ce8 commit 8a8f814
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/web-vue/components/color-picker/color-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { colors } from './colors';
import { HSV } from './interface';
import Panel from './panel';
import Trigger, { TriggerProps } from '../trigger';
import useMergeState from '../_hooks/use-merge-state';
import useState from '../_hooks/use-state';
import {
formatInputToHSVA,
Expand Down Expand Up @@ -133,10 +132,9 @@ export default defineComponent({
},
setup(props, { emit, slots }) {
const prefixCls = getPrefixCls('color-picker');
const [mergeValue, setMergeValue] = useMergeState(
props.defaultValue,
reactive({ value: props.modelValue })
);
const mergeValue = computed(() => {
return props.modelValue ?? props.defaultValue;
});

const formatInput = computed(() => {
return formatInputToHSVA(mergeValue.value || '');
Expand All @@ -149,6 +147,18 @@ export default defineComponent({
v: formatInput.value.v,
});

watch(
() => formatInput.value,
(value) => {
setAlpha(value.a);
setHsv({
h: value.h,
s: value.s,
v: value.v,
});
}
);

const color = computed(() => {
const rgb = hsvToRgb(hsv.value.h, hsv.value.s, hsv.value.v);
const hex = rgbToHex(rgb.r, rgb.g, rgb.b);
Expand Down Expand Up @@ -177,7 +187,6 @@ export default defineComponent({
});

watch(formatValue, (value) => {
setMergeValue(value);
emit('update:modelValue', value);
emit('change', value);
});
Expand Down

0 comments on commit 8a8f814

Please sign in to comment.