EccUtilsDesignCheckbox Component
Overview
The ecc-utils-design-checkbox component provides a standard checkbox input for forms, allowing users to select one or more options.
This component is a custom-styled checkbox that provides consistent behavior and appearance across browsers.
Usage
Basic Checkbox
This example shows a default checkbox.
Disabled Checkbox
This example shows a checkbox in a disabled state.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
checked | boolean | false | When true, the checkbox is checked. |
disabled | boolean | false | When true, disables the checkbox. |
name | string | "" | The name of the checkbox for form submission. |
value | string | "" | The value of the checkbox for form submission. |
invalid | boolean | false | When true, marks the checkbox as invalid, e.g. after an API rejected its value. |
checked
Controls the checked state of the checkbox.
<EccUtilsDesignCheckbox checked={true} />disabled
When true, the checkbox is non-interactive.
<EccUtilsDesignCheckbox disabled={true} />name
The name attribute, used when submitting the checkbox as part of a form.
<EccUtilsDesignCheckbox name="newsletter" />value
The value attribute, used when submitting the checkbox as part of a form.
<EccUtilsDesignCheckbox value="subscribe" />invalid
Marks the checkbox as invalid, e.g. when an API rejected its value (see Field errors): it gets a red border and aria-invalid="true". Clear it when the user changes the value or submits again. Unlike the other form controls, the checkbox has no error property: a message under the box wouldn't wrap next to its label, e.g. when the checkbox is at the end of a row. Render the message yourself, e.g. next to the label or above the form: with mapFieldErrors(), set invalid when fieldErrors has a message for the checkbox's field key, and show that message (it is not part of generalError, which holds only the errors that match no field).
<EccUtilsDesignCheckbox invalid={true} />Events
| Event Name | React Event Name | Detail Type | Description |
|---|---|---|---|
ecc-input-changed | onEccInputChanged | { checked: boolean, value: string } | Fired when the state of the checkbox changes. |
ecc-input-changed
Fires when the checkbox is checked or unchecked by the user.
<EccUtilsDesignCheckbox
onEccInputChanged={(event) => {
console.log(event.detail.checked, event.detail.value);
}}
/>