Checkbox

Checkboxes allow the user to toggle an option on or off.

Checkboxes allow the user to toggle an option on or off.

Checkbox

Use the checked attribute to activate the checkbox.

Checked

Add descriptive help text to a switch with the help-text attribute. For help texts that contain HTML, use the help-text slot instead.

Label

Use the required attribute to specify the input is a required field when using within a form.

Checked

Use the disabled attribute to disable the checkbox.

Disabled

Use the error-text attribute to customize the error message shown. Read more about error validation here .

Checked

Use the indeterminate attribute to make the checkbox indeterminate.

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 .

Checkbox
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.

Slots

NameDescription
(default)The checkbox's label.
help-textText that describes how to use the checkbox. Alternatively, you can use the `help-text` attribute.

Properties

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/AttributeReflectsTypeDefault
title
string''
name
string''
value
string
size
'small' | 'medium' | 'large''medium'
disabled
booleanfalse
checked
booleanfalse
indeterminate
booleanfalse
defaultChecked
booleanfalse
form
string''
required
booleanfalse
helpText
help-text
string''
errorText
error-text
string''
validity
validationMessage

Events

React EventDescriptionEvent Detail
ods-blurEmitted when the checkbox loses focus.--
ods-changeEmitted when the checked state changes.--
ods-focusEmitted when the checkbox gains focus.--
ods-inputEmitted when the checkbox receives input.--
ods-invalidEmitted when the form control has been checked for validity and its constraints aren't satisfied.--

Methods

NameDescriptionArguments
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.--

Parts

NameDescription
baseThe component's base wrapper.
controlThe square container that wraps the checkbox's checked state.
control--checkedMatches the control part when the checkbox is checked.
control--indeterminateMatches the control part when the checkbox is indeterminate.
checked-iconThe checked icon, an `<ods-icon>` element.
indeterminate-iconThe indeterminate icon, an `<ods-icon>` element.
labelThe container that wraps the checkbox's label.
form-control-help-textThe help text's wrapper.
form-control-error-textThe error text's wrapper.

Dependencies

This component automatically imports the following dependencies.

  • ods-icon

Search