diff --git a/packages/vant/src/checkbox/Checker.tsx b/packages/vant/src/checkbox/Checker.tsx index 6c0e6d69f..b2ab66091 100644 --- a/packages/vant/src/checkbox/Checker.tsx +++ b/packages/vant/src/checkbox/Checker.tsx @@ -148,6 +148,8 @@ export default defineComponent({ }; const renderLabel = () => { + const { checked } = props; + if (slots.default) { return ( - {slots.default()} + {slots.default({ checked, disabled: disabled.value })} ); } diff --git a/packages/vant/src/checkbox/README.md b/packages/vant/src/checkbox/README.md index 5ba1e0bd4..1759ee3c0 100644 --- a/packages/vant/src/checkbox/README.md +++ b/packages/vant/src/checkbox/README.md @@ -363,7 +363,7 @@ export default { | Name | Description | SlotProps | | ------- | ------------ | ----------------------------------------- | -| default | Custom label | - | +| default | Custom label | _{ checked: boolean, disabled: boolean }_ | | icon | Custom icon | _{ checked: boolean, disabled: boolean }_ | ### CheckboxGroup Methods diff --git a/packages/vant/src/checkbox/README.zh-CN.md b/packages/vant/src/checkbox/README.zh-CN.md index 947f03385..7615b077e 100644 --- a/packages/vant/src/checkbox/README.zh-CN.md +++ b/packages/vant/src/checkbox/README.zh-CN.md @@ -382,7 +382,7 @@ export default { | 名称 | 说明 | 参数 | | ------- | ---------- | ----------------------------------------- | -| default | 自定义文本 | - | +| default | 自定义文本 | _{ checked: boolean, disabled: boolean }_ | | icon | 自定义图标 | _{ checked: boolean, disabled: boolean }_ | ### CheckboxGroup 方法 diff --git a/packages/vant/src/checkbox/test/index.spec.ts b/packages/vant/src/checkbox/test/index.spec.ts index 7ea61a7d9..26bd8a444 100644 --- a/packages/vant/src/checkbox/test/index.spec.ts +++ b/packages/vant/src/checkbox/test/index.spec.ts @@ -116,3 +116,20 @@ test('should render icon slot correctly', async () => { expect(wrapper.find('.van-checkbox__icon').html()).toMatchSnapshot(); }); + +test('should render label slot correctly', async () => { + const slot = vi.fn(); + const wrapper = mount(Checkbox, { + slots: { + default: slot, + }, + }); + + expect(slot.mock.calls[0]).toEqual([{ checked: false, disabled: false }]); + + await wrapper.setProps({ modelValue: true }); + expect(slot.mock.calls[1]).toEqual([{ checked: true, disabled: false }]); + + await wrapper.setProps({ disabled: true }); + expect(slot.mock.calls[2]).toEqual([{ checked: true, disabled: true }]); +}); diff --git a/packages/vant/src/radio/README.md b/packages/vant/src/radio/README.md index f8f1b5716..2929b93ed 100644 --- a/packages/vant/src/radio/README.md +++ b/packages/vant/src/radio/README.md @@ -229,7 +229,7 @@ import type { | Name | Description | SlotProps | | ------- | ------------ | ----------------------------------------- | -| default | Custom label | - | +| default | Custom label | _{ checked: boolean, disabled: boolean }_ | | icon | Custom icon | _{ checked: boolean, disabled: boolean }_ | ## Theming diff --git a/packages/vant/src/radio/README.zh-CN.md b/packages/vant/src/radio/README.zh-CN.md index 8d73df97d..242a3e961 100644 --- a/packages/vant/src/radio/README.zh-CN.md +++ b/packages/vant/src/radio/README.zh-CN.md @@ -229,7 +229,7 @@ export default { | 名称 | 说明 | 参数 | | ------- | ---------- | ----------------------------------------- | -| default | 自定义文本 | - | +| default | 自定义文本 | _{ checked: boolean, disabled: boolean }_ | | icon | 自定义图标 | _{ checked: boolean, disabled: boolean }_ | ### 类型定义