Checkboxes allow the user to toggle an option on or off.
Checkboxes allow the user to toggle an option on or off.
Use the checked attribute to activate the checkbox.
Add descriptive help text to a switch with the help-text attribute. For help texts that contain HTML, use the help-text slot instead.
Use the required attribute to specify the input is a required field when using within a form.
Use the disabled attribute to disable the checkbox.
Use the error-text attribute to customize the error message shown. Read more about error validation here .
Use the indeterminate attribute to make the checkbox indeterminate.
You can listen for the ods-change event to determine when a checkbox is updated. You can see other checkbox events here . You can also see how a checkbox is used in forms by checking out the form section .
import '@ods/components/web.checkbox';Note: You only need to import a web component once in your code, as it registers itself globally when defined, allowing you to use it anywhere within your application without needing to re-import it each time you want to use the component.
This component is still in development and cannot be imported at this time.
| Name | Description |
|---|---|
| (default) | The checkbox's label. |
| help-text | Text that describes how to use the checkbox. Alternatively, you can use the `help-text` attribute. |
Please note, both DOM properties and HTML attributes are shown in the table below. Unless otherwise specified, the property and attribute names are identical.
| Property/Attribute | Reflects | Type | Default |
|---|---|---|---|
title | string | '' | |
name | string | '' | |
value | string | ||
size | 'small' | 'medium' | 'large' | 'medium' | |
disabled | boolean | false | |
checked | boolean | false | |
indeterminate | boolean | false | |
defaultChecked | boolean | false | |
form | string | '' | |
required | boolean | false | |
helpText | string | '' | |
errorText | string | '' | |
validity | |||
validationMessage |
| React Event | Description | Event Detail |
|---|---|---|
| ods-blur | Emitted when the checkbox loses focus. | -- |
| ods-change | Emitted when the checked state changes. | -- |
| ods-focus | Emitted when the checkbox gains focus. | -- |
| ods-input | Emitted when the checkbox receives input. | -- |
| ods-invalid | Emitted when the form control has been checked for validity and its constraints aren't satisfied. | -- |
| Name | Description | Arguments |
|---|---|---|
| click() | Simulates a click on the checkbox. | -- |
| focus() | Sets focus on the checkbox. | -- |
| blur() | Removes focus from the checkbox. | -- |
| checkValidity() | Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. | -- |
| getForm() | Gets the associated form, if one exists. | -- |
| reportValidity() | Checks for validity and shows the browser's validation message if the control is invalid. | -- |
| setCustomValidity() | Sets a custom validation message. The value provided will be shown to the user when the form is submitted. To clear the custom validation message, call this method with an empty string. | -- |
| Name | Description |
|---|---|
| base | The component's base wrapper. |
| control | The square container that wraps the checkbox's checked state. |
| control--checked | Matches the control part when the checkbox is checked. |
| control--indeterminate | Matches the control part when the checkbox is indeterminate. |
| checked-icon | The checked icon, an `<ods-icon>` element. |
| indeterminate-icon | The indeterminate icon, an `<ods-icon>` element. |
| label | The container that wraps the checkbox's label. |
| form-control-help-text | The help text's wrapper. |
| form-control-error-text | The error text's wrapper. |
This component automatically imports the following dependencies.