Checkbox
Brief Introduction
The checkbox component is used for users to select one or more options from multiple choices. mengyue-components has encapsulated it and performed vitest testing. There are two ways to implement checkbox tags: <MYCheckbox /> or <MYCheckbox></MYCheckbox><MYCheckbox-group /> or <MYCheckbox-group></MYCheckbox-group> for checkbox groups.
Basic Usage
Single Checkbox
Use modelValue to bind the value of a single checkbox.
Code Demo
展开代码
Checkbox Group
Use <MYCheckbox-group></MYCheckbox-group> to group checkboxes together.
Code Demo
展开代码
Layout Direction
Vertical Arrangement
Use direction="vertical" to arrange checkboxes vertically.
Code Demo
展开代码
Disabled State
Disable Entire Group
Disable the entire checkbox group.
Code Demo
展开代码
Custom Spacing
Use the gap property to control the spacing between checkboxes.
Code Demo
展开代码
API Reference
MYCheckboxGroup Props
| Parameter | Description | Type | Options | Default |
|---|---|---|---|---|
| modelValue | Bound value | array | — | [] |
| direction | Layout direction | string | horizontal / vertical | horizontal |
| disabled | Whether disabled | boolean | — | false |
| gap | Spacing | string | Supports CSS units | 12px |
MYCheckbox Props
| Parameter | Description | Type | Options | Default |
|---|---|---|---|---|
| modelValue | Bound value | boolean | — | false |
| value | Option value | string | number | — | — |
| disabled | Whether disabled | boolean | — | false |
Type Definitions
typescript
interface CheckboxGroupProps {
modelValue?: (string | number)[];
direction?: 'horizontal' | 'vertical';
disabled?: boolean;
gap?: string;
}
interface CheckboxProps {
modelValue?: boolean;
value?: string | number;
disabled?: boolean;
}