Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Checker): add checked and disabled params to the default slot #12436

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/vant/src/checkbox/Checker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export default defineComponent({
};

const renderLabel = () => {
const { checked } = props;

if (slots.default) {
return (
<span
Expand All @@ -156,7 +158,7 @@ export default defineComponent({
{ disabled: disabled.value },
])}
>
{slots.default()}
{slots.default({ checked, disabled: disabled.value })}
</span>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vant/src/checkbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/vant/src/checkbox/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export default {

| 名称 | 说明 | 参数 |
| ------- | ---------- | ----------------------------------------- |
| default | 自定义文本 | - |
| default | 自定义文本 | _{ checked: boolean, disabled: boolean }_ |
| icon | 自定义图标 | _{ checked: boolean, disabled: boolean }_ |

### CheckboxGroup 方法
Expand Down
17 changes: 17 additions & 0 deletions packages/vant/src/checkbox/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }]);
});
2 changes: 1 addition & 1 deletion packages/vant/src/radio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/vant/src/radio/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export default {

| 名称 | 说明 | 参数 |
| ------- | ---------- | ----------------------------------------- |
| default | 自定义文本 | - |
| default | 自定义文本 | _{ checked: boolean, disabled: boolean }_ |
| icon | 自定义图标 | _{ checked: boolean, disabled: boolean }_ |

### 类型定义
Expand Down