@mfp-design-system/checkbox
v3.0.0
Published
Checkbox web component for the mfp-design-system, built with Lit.
Readme
@mfp-design-system/checkbox
A Lit-based <mfp-checkbox> web component, fully form-associated.
Install
npm install @mfp-design-system/checkbox @mfp-design-system/tokensUsage
import '@mfp-design-system/checkbox';
import '@mfp-design-system/tokens/css';<mfp-checkbox label="Subscribe"></mfp-checkbox>
<mfp-checkbox checked label="Pre-checked"></mfp-checkbox>
<mfp-checkbox indeterminate label="Select all"></mfp-checkbox>
<mfp-checkbox required> I agree to the <a href="#">terms</a> </mfp-checkbox>
<form>
<mfp-checkbox name="agree" value="yes" required></mfp-checkbox>
<button type="submit">Submit</button>
</form>API
| Attribute | Type | Default | Description |
| --------------- | --------- | ------- | ---------------------------------------------------------- |
| checked | boolean | false | Checked state |
| indeterminate | boolean | false | Indeterminate state (overrides visual check) |
| disabled | boolean | false | Disables the checkbox |
| required | boolean | false | Marks as required for form validation |
| name | string | '' | Form field name |
| value | string | 'on' | Value submitted with the form when checked |
| label | string | '' | Label text (use the default slot for rich content instead) |
Events
change— fires when the user toggles the checkbox.event.detail.checkedis the new state.
Forms
<mfp-checkbox> is form-associated via ElementInternals:
- When
checked, itsvalueis submitted undername; when unchecked, nothing is submitted requiredtriggersvalueMissingvalidation when uncheckedcheckValidity()andreportValidity()mirror native methods
Slots
- (default) — label content (used when the
labelattribute is empty; lets you include links/icons)
Shadow parts
box, label.
