fix: Checkbox checked optional cannot control state issue (#2046) (#2122)

Co-authored-by: yangyu8 <yangyu8@kingsoft.com>
This commit is contained in:
msidolphin 2021-06-14 20:20:02 +08:00 committed by GitHub
parent e2e3ace5db
commit f9e4da734d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -330,4 +330,12 @@ describe('check-button', () => {
expect(wrapper.vm.checked).toBe(true)
expect(wrapper.vm.checklist).toEqual(['a'])
})
test('checked', () => {
const wrapper = _mount(
`<el-checkbox checked />`,
() => ({}))
expect(wrapper.find('.el-checkbox').classes().toString()).toMatch('is-checked')
})
})

View File

@ -34,7 +34,7 @@ export const useCheckboxGroup = () => {
}
const useModel = (props: ICheckboxProps) => {
let selfModel = false
const selfModel = ref(false)
const { emit } = getCurrentInstance()
const { isGroup, checkboxGroup } = useCheckboxGroup()
const isLimitExceeded = ref(false)
@ -43,7 +43,7 @@ const useModel = (props: ICheckboxProps) => {
get() {
return isGroup.value
? store.value
: props.modelValue ?? selfModel
: props.modelValue ?? selfModel.value
},
set(val: unknown) {
@ -60,7 +60,7 @@ const useModel = (props: ICheckboxProps) => {
isLimitExceeded.value === false && checkboxGroup?.changeEvent?.(val)
} else {
emit(UPDATE_MODEL_EVENT, val)
selfModel = val as boolean
selfModel.value = val as boolean
}
},
})