diff --git a/docs/en-US/component/color-picker.md b/docs/en-US/component/color-picker.md index d50370e59f..4e2697e7b1 100644 --- a/docs/en-US/component/color-picker.md +++ b/docs/en-US/component/color-picker.md @@ -60,20 +60,24 @@ color-picker/sizes | predefine | predefined color options | ^[object]`string[]` | — | | validate-event | whether to trigger form validation | ^[boolean] | true | | tabindex | ColorPicker tabindex | ^[string] / ^[number] | 0 | -| label | ColorPicker aria-label | ^[string] | — | +| label ^(a11y) | ColorPicker aria-label | ^[string] | — | | id | ColorPicker id | ^[string] | — | ### Events -| Name | Description | Type | -| ------------- | ---------------------------------------------- | ------------------------------------ | -| change | triggers when input value changes | ^[Function]`(value: string) => void` | -| active-change | triggers when the current active color changes | ^[Function]`(value: string) => void` | +| Name | Description | Type | +| -------------- | ---------------------------------------------- | ---------------------------------------- | +| change | triggers when input value changes | ^[Function]`(value: string) => void` | +| active-change | triggers when the current active color changes | ^[Function]`(value: string) => void` | +| focus ^(2.4.0) | triggers when Component focuses | ^[Function]`(event: FocusEvent) => void` | +| blur ^(2.4.0) | triggers when Component blurs | ^[Function]`(event: FocusEvent) => void` | ### Exposes -| Name | Description | Type | -| ------------- | ------------------------- | ----------------------- | -| color | current color object | ^[object]`Color` | -| show ^(2.3.3) | manually show ColorPicker | ^[Function]`() => void` | -| hide ^(2.3.3) | manually hide ColorPicker | ^[Function]`() => void` | +| Name | Description | Type | +| --------------- | ------------------------- | ----------------------- | +| color | current color object | ^[object]`Color` | +| show ^(2.3.3) | manually show ColorPicker | ^[Function]`() => void` | +| hide ^(2.3.3) | manually hide ColorPicker | ^[Function]`() => void` | +| focus ^(2.3.13) | focus the picker element | ^[Function]`() => void` | +| blur ^(2.3.13) | blur the picker element | ^[Function]`() => void` | diff --git a/packages/components/color-picker/__tests__/color-picker.test.tsx b/packages/components/color-picker/__tests__/color-picker.test.tsx index 36b6b0dec7..9913bae5cc 100644 --- a/packages/components/color-picker/__tests__/color-picker.test.tsx +++ b/packages/components/color-picker/__tests__/color-picker.test.tsx @@ -453,4 +453,20 @@ describe('Color-picker', () => { expect(formItem.attributes().role).toBe('group') }) }) + + it('it will target the focus & blur', async () => { + const focusHandler = vi.fn() + const blurHandler = vi.fn() + const wrapper = mount(() => ( + + )) + + await nextTick() + await wrapper.find('.el-color-picker').trigger('focus') + expect(focusHandler).toHaveBeenCalledTimes(1) + + await wrapper.find('.el-color-picker').trigger('blur') + expect(blurHandler).toHaveBeenCalledTimes(1) + wrapper.unmount() + }) }) diff --git a/packages/components/color-picker/src/color-picker.ts b/packages/components/color-picker/src/color-picker.ts index 6b5924febd..4e15bdeec8 100644 --- a/packages/components/color-picker/src/color-picker.ts +++ b/packages/components/color-picker/src/color-picker.ts @@ -70,6 +70,8 @@ export const colorPickerEmits = { [UPDATE_MODEL_EVENT]: (val: string | null) => isString(val) || isNil(val), [CHANGE_EVENT]: (val: string | null) => isString(val) || isNil(val), activeChange: (val: string | null) => isString(val) || isNil(val), + focus: (event: FocusEvent) => event instanceof FocusEvent, + blur: (event: FocusEvent) => event instanceof FocusEvent, } export type ColorPickerProps = ExtractPropTypes diff --git a/packages/components/color-picker/src/color-picker.vue b/packages/components/color-picker/src/color-picker.vue index deb3884542..b3d7711438 100644 --- a/packages/components/color-picker/src/color-picker.vue +++ b/packages/components/color-picker/src/color-picker.vue @@ -12,9 +12,10 @@ trigger="click" :transition="`${ns.namespace.value}-zoom-in-top`" persistent + @hide="setShowPicker(false)" >