Checkbox
Checkboxes allow the user to select one or more items from a set.
Importing
To use the checkbox component, first you need to register the component inside the page. You can register the component manually by importing the register function:
ts
import { register } from "@tapsioss/web-components/checkbox";
register(); // Now the checkbox component is ready to use!
ts
import { registerCheckbox } from "@tapsioss/web-components";
registerCheckbox(); // Now the checkbox component is ready to use!
Also you can automatically register the component by importing it with the following approach:
ts
import "@tapsioss/web-components/checkbox/element";
TIP
If you want to use all the component in your app, you can call registerAll
at the root of your project.
ts
import { registerAll } from "@tapsioss/web-components";
registerAll(); // All the components are now available
In the React package, you can easily add the component using the following code:
ts
import { Checkbox } from "@tapsioss/react-components";
Component Usage
html
<tapsi-checkbox></tapsi-checkbox>
tsx
<Checkbox />
Properties
Name | Attribute Name | Description | Type | Default Value |
---|---|---|---|---|
checked | checked | Whether or not the checkbox is selected. | boolean | false |
indeterminate | indeterminate | Whether or not the checkbox is indeterminate. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#indeterminate_state_checkboxes | boolean | false |
value | value | The value of the checkbox that is submitted with a form when selected. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value | string | "on" |
error | error | Whether the checkbox has error. | boolean | false |
required | required | Indicates that the user must specify a value for the input before the owning form can be submitted and will render an error state when reportValidity() is invoked when value is empty.https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required | boolean | false |
label | label | Defines a string value that can be used to name input. https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label | string | "" |
labelledBy | labelledby | Identifies the element (or elements) that labels the input. https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby | string | "" |
autofocus | autofocus | Indicates that the element should be focused on page load. https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus | boolean | false |
Events
Name | Description | Type | Bubbles | Cancelable |
---|---|---|---|---|
change | Fires when the user modifies the element's value. Unlike the input event, the change event is not necessarily fired for each alteration to an element's value . | Event | ✅ | ❌ |
input | Fires when the value of an input element has been changed as a direct result of a user action. | Event | ✅ | ❌ |