Checkbox
Introduction
The checkbox component is used for users to select one or more options from multiple choices. mengyue-components has encapsulated this component and conducted vitest testing. There are two tags for implementing checkboxes: <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 Layout
Use direction="vertical" to arrange checkboxes vertically.
Code Demo
展开代码
Disabled State
Entire Group Disabled
Disable the entire checkbox group.
Code Demo
展开代码
Custom Spacing
Use the gap prop 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 |
| checkStrictly | Whether parent-child are strictly linked | boolean | — | false |
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;
}