fix: [el-checkbox-group]: default value adjusted to empty array (#4316)

fix #4300
This commit is contained in:
msidolphin 2021-12-21 14:38:54 +08:00 committed by GitHub
parent 8f57bf610e
commit 1d0d0053fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -106,7 +106,7 @@ checkbox/with-border
| Attribute | Description | Type | Accepted Values | Default |
| --------------------- | ------------------------------------------------- | ------- | ---------------------- | ------- |
| model-value / v-model | binding value | array | — | |
| model-value / v-model | binding value | array | — | [] |
| size | size of checkbox | string | large / default /small | — |
| disabled | whether the nesting checkboxes are disabled | boolean | — | false |
| min | minimum number of checkbox checked | number | — | — |

View File

@ -95,6 +95,24 @@ describe('Checkbox', () => {
expect(vm.checkList).toContain('b')
})
test('checkbox group without modelValue', async () => {
const wrapper = _mount(
`
<el-checkbox-group v-model="checkList">
<el-checkbox label="a" ref="a"></el-checkbox>
<el-checkbox label="b" ref="b"></el-checkbox>
<el-checkbox label="c" ref="c"></el-checkbox>
<el-checkbox label="d" ref="d"></el-checkbox>
</el-checkbox-group>
`,
() => ({ checkList: undefined })
)
const vm = wrapper.vm
await wrapper.findComponent({ ref: 'a' }).trigger('click')
expect(vm.checkList.length).toBe(1)
expect(vm.checkList).toContain('a')
})
test('checkbox group change', async () => {
const wrapper = _mount(
`

View File

@ -26,8 +26,8 @@ export default defineComponent({
props: {
modelValue: {
type: [Object, Boolean, Array],
default: () => undefined,
type: Array,
default: () => [],
},
disabled: Boolean,
min: {