Skip to content

Commit

Permalink
fix(components): [color-picker] can't select predefine value (#8205)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed Jun 28, 2022
1 parent ecc8003 commit 920f1fc
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/components/color-picker/src/index.vue
Expand Up @@ -67,7 +67,7 @@
:aria-label="buttonAriaLabel"
:aria-labelledby="buttonAriaLabelledby"
:aria-description="
t('el.colorpicker.description', { color: modelValue })
t('el.colorpicker.description', { color: modelValue || '' })
"
:tabindex="tabindex"
@keydown.enter="handleTrigger"
Expand Down Expand Up @@ -193,20 +193,21 @@ export default defineComponent({
}
)
const hue = ref(null)
const svPanel = ref(null)
const alpha = ref(null)
const hue = ref<InstanceType<typeof HueSlider>>()
const svPanel = ref<InstanceType<typeof SvPanel>>()
const alpha = ref<InstanceType<typeof AlphaSlider>>()
const popper = ref(null)
// active-change is used to prevent modelValue changes from triggering.
let shouldActiveChange = true
// data
const color = reactive(
new Color({
enableAlpha: props.showAlpha,
format: props.colorFormat,
format: props.colorFormat || '',
value: props.modelValue,
})
)
type ColorType = typeof color
const showPicker = ref(false)
const showPanelColor = ref(false)
const customInput = ref('')
Expand Down Expand Up @@ -264,7 +265,7 @@ export default defineComponent({
)
// methods
function displayedRgb(color, showAlpha) {
function displayedRgb(color: ColorType, showAlpha: boolean) {
if (!(color instanceof Color)) {
throw new TypeError('color should be instance of _color Class')
}
Expand All @@ -275,7 +276,7 @@ export default defineComponent({
: `rgb(${r}, ${g}, ${b})`
}
function setShowPicker(value) {
function setShowPicker(value: boolean) {
showPicker.value = value
}
Expand All @@ -291,7 +292,10 @@ export default defineComponent({
if (props.modelValue) {
color.fromString(props.modelValue)
} else {
showPanelColor.value = false
color.value = ''
nextTick(() => {
showPanelColor.value = false
})
}
})
}
Expand All @@ -315,7 +319,7 @@ export default defineComponent({
nextTick(() => {
const newColor = new Color({
enableAlpha: props.showAlpha,
format: props.colorFormat,
format: props.colorFormat || '',
value: props.modelValue,
})
if (!color.compare(newColor)) {
Expand Down

0 comments on commit 920f1fc

Please sign in to comment.