Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components): [color-picker] add custom trigger #16684

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/en-US/component/color-picker.md
Expand Up @@ -45,6 +45,14 @@ color-picker/sizes

:::

## Custom trigger

:::demo

color-picker/custom-trigger

:::

## API

### Attributes
Expand Down Expand Up @@ -75,6 +83,12 @@ color-picker/sizes
| focus ^(2.4.0) | triggers when Component focuses | ^[Function]`(event: FocusEvent) => void` |
| blur ^(2.4.0) | triggers when Component blurs | ^[Function]`(event: FocusEvent) => void` |

### Slots

| Name | Description | Type |
| -------------- | ---------------------------------------------- | ---------------------------------------- |
| default | custom trigger | - |

### Exposes

| Name | Description | Type |
Expand Down
11 changes: 11 additions & 0 deletions docs/examples/color-picker/custom-trigger.vue
@@ -0,0 +1,11 @@
<template>
<el-color-picker v-model="color">
<el-button :color="color">trigger</el-button>
</el-color-picker>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const color = ref('rgba(19, 206, 102, 0.8)')
</script>
16 changes: 16 additions & 0 deletions packages/components/color-picker/__tests__/color-picker.test.tsx
Expand Up @@ -2,6 +2,7 @@ import { nextTick, ref } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, it, vi } from 'vitest'
import { ElFormItem } from '@element-plus/components/form'
import Button from '@element-plus/components/button'
import ColorPicker from '../src/color-picker.vue'
import type { ComponentPublicInstance } from 'vue'

Expand Down Expand Up @@ -469,4 +470,19 @@ describe('Color-picker', () => {
expect(blurHandler).toHaveBeenCalledTimes(1)
wrapper.unmount()
})

it('custom trigger', async () => {
const wrapper = mount(() => (
<ColorPicker>
<Button>trigger</Button>
</ColorPicker>
))

await nextTick()
const trigger = wrapper.find('.el-button')
await trigger.trigger('click')
const dropdown = document.querySelector('.el-color-dropdown')
expect(dropdown).toBeTruthy()
wrapper.unmount()
})
})
5 changes: 4 additions & 1 deletion packages/components/color-picker/src/color-picker.vue
Expand Up @@ -76,7 +76,10 @@
@blur="handleBlur"
>
<div v-if="colorDisabled" :class="ns.be('picker', 'mask')" />
<div :class="ns.be('picker', 'trigger')" @click="handleTrigger">
<div v-if="$slots.default" @click="handleTrigger">
<slot />
</div>
<div v-else :class="ns.be('picker', 'trigger')" @click="handleTrigger">
<span :class="[ns.be('picker', 'color'), ns.is('alpha', showAlpha)]">
<span
:class="ns.be('picker', 'color-inner')"
Expand Down