diff --git a/packages/components/checkbox/__tests__/checkbox.test.tsx b/packages/components/checkbox/__tests__/checkbox.test.tsx index 96128e4d19..e17a384ff3 100644 --- a/packages/components/checkbox/__tests__/checkbox.test.tsx +++ b/packages/components/checkbox/__tests__/checkbox.test.tsx @@ -21,6 +21,11 @@ describe('Checkbox', () => { expect(wrapper.classes('is-checked')).toBe(false) }) + test('label set to number 0', async () => { + const wrapper = mount(() => ) + expect(wrapper.find('.el-checkbox__label').text()).toBe('0') + }) + describe('no v-model', () => { test('checkbox without label', async () => { const checked = ref(false) diff --git a/packages/components/checkbox/src/checkbox.ts b/packages/components/checkbox/src/checkbox.ts index 7701672533..8ee2705f2c 100644 --- a/packages/components/checkbox/src/checkbox.ts +++ b/packages/components/checkbox/src/checkbox.ts @@ -20,6 +20,7 @@ export const checkboxProps = { */ label: { type: [String, Boolean, Number, Object], + default: undefined, }, /** * @description Set indeterminate state, only responsible for style control diff --git a/packages/components/checkbox/src/composables/use-checkbox-status.ts b/packages/components/checkbox/src/composables/use-checkbox-status.ts index 696e91bcf9..c47a5e387d 100644 --- a/packages/components/checkbox/src/composables/use-checkbox-status.ts +++ b/packages/components/checkbox/src/composables/use-checkbox-status.ts @@ -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(() => { - return !!(slots.default || props.label) + return !!slots.default || !isNil(props.label) }) return {