refactor(components): [checkbox] set the label default value to undefined (#14011)

* fix(components): [checkbox] allow the label value to be number 0

* fix: update computed

* test: add test case

* fix: update
This commit is contained in:
btea 2023-10-11 15:00:09 +08:00 committed by GitHub
parent 0137d4cfcb
commit e32cef1d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View File

@ -21,6 +21,11 @@ describe('Checkbox', () => {
expect(wrapper.classes('is-checked')).toBe(false)
})
test('label set to number 0', async () => {
const wrapper = mount(() => <Checkbox label={0} />)
expect(wrapper.find('.el-checkbox__label').text()).toBe('0')
})
describe('no v-model', () => {
test('checkbox without label', async () => {
const checked = ref(false)

View File

@ -20,6 +20,7 @@ export const checkboxProps = {
*/
label: {
type: [String, Boolean, Number, Object],
default: undefined,
},
/**
* @description Set indeterminate state, only responsible for style control

View File

@ -1,5 +1,5 @@
import { computed, inject, ref, toRaw } from 'vue'
import { isEqual } from 'lodash-unified'
import { isEqual, isNil } from 'lodash-unified'
import { useFormSize } from '@element-plus/components/form'
import { isArray, isBoolean, isObject } from '@element-plus/utils'
import { checkboxGroupContextKey } from '../constants'
@ -41,7 +41,7 @@ export const useCheckboxStatus = (
const checkboxSize = useFormSize(computed(() => checkboxGroup?.size?.value))
const hasOwnLabel = computed<boolean>(() => {
return !!(slots.default || props.label)
return !!slots.default || !isNil(props.label)
})
return {