fix(components): [color-picker] supports dynamic change of colorFormat (#18135)

* feat(components): [color-picker] supports dynamic change of colorFormat

* test(components): [color-picker] test cases with fixes added
This commit is contained in:
尘随风染 2024-09-12 14:59:46 +08:00 committed by GitHub
parent b2a17f0689
commit 30a6d3b7a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -498,4 +498,25 @@ describe('Color-picker', () => {
expect(blurHandler).toHaveBeenCalled()
wrapper.unmount()
})
it('when colorFormat prop changes, the color format and v-model binding values should be updated', async () => {
const color = ref('#00FF00')
const colorFormat = ref('hex')
const wrapper = mount(() => (
<ColorPicker v-model={color.value} color-format={colorFormat.value} />
))
colorFormat.value = 'rgb'
await nextTick()
const colorPickerWrapper = wrapper.findComponent(ColorPicker)
const customInput = colorPickerWrapper.findComponent({
ref: 'inputRef',
})
expect(colorPickerWrapper.vm.color.format).toBe('rgb')
expect(color.value).toBe('rgb(0, 255, 0)')
expect(
customInput.find<HTMLInputElement>('.el-input__inner').element.value
).toBe('rgb(0, 255, 0)')
wrapper.unmount()
})
})

View File

@ -363,6 +363,17 @@ watch(
}
)
watch(
() => props.colorFormat,
() => {
if (props.colorFormat) {
color.format = props.colorFormat
color.doOnChange()
emit(UPDATE_MODEL_EVENT, color.value)
}
}
)
watch(
() => currentColor.value,
(val) => {