fix(components): [checkbox] fix type error (#8937)

* fix(components): [checkbox] fix type error

* fix(components): [checkbox] fix type error
This commit is contained in:
LIUCHAO 2022-07-25 19:40:07 +08:00 committed by GitHub
parent 1861a383ef
commit 44f48c65af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 13 deletions

View File

@ -1,4 +1,3 @@
// @ts-nocheck
import { nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
@ -6,9 +5,6 @@ import { ElFormItem } from '@element-plus/components/form'
import Checkbox from '../src/checkbox.vue'
import CheckboxButton from '../src/checkbox-button.vue'
import CheckboxGroup from '../src/checkbox-group.vue'
import type { VueWrapper } from '@vue/test-utils'
import type { FormItemInstance } from '@element-plus/components/form'
import type { CheckboxInstance } from '@element-plus/components/checkbox'
const _mount = (
template: string,
@ -59,7 +55,7 @@ describe('Checkbox', () => {
describe('disabled', () => {
test('checkbox without label', async () => {
const wrapper: VueWrapper<FormItemInstance> = _mount(
const wrapper = _mount(
`<el-form-item label="test">
<el-checkbox ref="check" v-model="checkbox" disabled/>
</el-form-item>`,
@ -75,7 +71,7 @@ describe('Checkbox', () => {
})
test('checkbox with label attribute', async () => {
const wrapper: VueWrapper<CheckboxInstance> = _mount(
const wrapper = _mount(
'<el-checkbox v-model="checkbox" disabled label="a"/>',
() => ({ checkbox: false })
)
@ -90,7 +86,7 @@ describe('Checkbox', () => {
describe('change event', () => {
test('checkbox without label', async () => {
const wrapper: VueWrapper<FormItemInstance> = _mount(
const wrapper = _mount(
`<el-form-item label="test">
<el-checkbox ref="check" v-model="checked" @change="onChange" />
</el-form-item>`,
@ -112,7 +108,7 @@ describe('Checkbox', () => {
})
test('checkbox with label attribute', async () => {
const wrapper: VueWrapper<CheckboxInstance> = _mount(
const wrapper = _mount(
`<el-checkbox v-model="checked" label="Foobar" @change="onChange" />`,
() => ({
data: null,
@ -132,7 +128,7 @@ describe('Checkbox', () => {
})
test('checkbox with label as slot content', async () => {
const wrapper: VueWrapper<CheckboxInstance> = _mount(
const wrapper = _mount(
`<el-checkbox v-model="checked" @change="onChange">Foobar</el-checkbox>`,
() => ({
data: null,

View File

@ -12,7 +12,6 @@
</template>
<script lang="ts" setup>
// @ts-nocheck
import { computed, nextTick, provide, toRefs, watch } from 'vue'
import { UPDATE_MODEL_EVENT } from '@element-plus/constants'
import { debugWarn } from '@element-plus/utils'
@ -23,6 +22,7 @@ import {
useCheckboxGroupId,
useCheckboxGroupProps,
} from './checkbox'
import type { CheckboxValueType } from './checkbox'
defineOptions({
name: 'ElCheckboxGroup',
@ -38,7 +38,7 @@ const { groupId, isLabeledByFormItem } = useCheckboxGroupId(props, {
const checkboxGroupSize = useSize()
const ns = useNamespace('checkbox')
const changeEvent = (value) => {
const changeEvent = (value: CheckboxValueType[]) => {
emit(UPDATE_MODEL_EVENT, value)
nextTick(() => {
emit('change', value)
@ -49,15 +49,15 @@ const modelValue = computed({
get() {
return props.modelValue
},
set(val) {
set(val: CheckboxValueType[]) {
changeEvent(val)
},
})
provide('CheckboxGroup', {
name: 'ElCheckboxGroup',
modelValue,
...toRefs(props),
modelValue,
checkboxGroupSize,
changeEvent,
})