mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-21 01:02:59 +08:00
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:
parent
b2a17f0689
commit
30a6d3b7a3
@ -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()
|
||||
})
|
||||
})
|
||||
|
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user