Checkbox
<afp-checkbox>
The Checkbox component allows users to select or deselect a single option. It supports multiple states including checked, unchecked, disabled, and indeterminate.
Examples #
Shapes #
Use the shape attribute to set the shape of the checkbox. Available shapes are square and rounded.
Sizes #
Use the size attribute to set the size of the checkbox. Available sizes are small, medium, and large.
Hint #
Use the hint attribute to provide additional information below the checkbox.
Value #
Use the afp-value-changed event to listen for value changes.
Checked #
Use the checked attribute to render a checkbox in the checked state.
Disabled #
Use the disabled attribute to render a checkbox in the disabled state.
Invalid #
Use the invalid attribute to render a checkbox in the invalid state with an error message.
Indeterminate #
Use the indeterminate attribute to render a checkbox in the indeterminate state.
Custom Icons #
Use the checked-icon and indeterminate-icon slots to provide custom icons for the checked and indeterminate states.
Customization #
Use the --afp-checkbox-color and --afp-checkbox-background CSS variables to customize the checkbox appearance.
Properties
Learn more about properties.
| Name | Description | Reflects | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
checked
|
Checked state of the checkbox.
Type
boolean
Default
false |
|
||||||||||
defaultchecked
|
Default checked attribute of the checkbox. The checkbox is initialized with checked = true when defaultchecked is true.
Type
boolean
Default
false |
|||||||||||
hideLabel
hidelabel
|
Hides the label visually
Type
boolean
|
|
||||||||||
disabled
|
Disabled state of the checkbox.
Type
boolean
Default
false |
|
||||||||||
indeterminate
|
Indeterminate state of the checkbox.
Type
boolean
Default
false |
|
||||||||||
invalid
|
Error message shown below the checkbox when present. Sets `aria-invalid`.
Provide a non-empty string to put the component in an error state.
Type
string
|
|||||||||||
hint
|
hint footer property of checkbox
Type
string
|
|
||||||||||
shape
|
shape of the checkbox
Type
AfpShape
Default
AfpShape.ROUNDED |
|
||||||||||
name
|
Name of the input element.
Type
string
|
|||||||||||
required
|
Required attribute of the checkbox.
Type
boolean
Default
false |
|
||||||||||
size
|
Size of the checkbox
Type
AfpSize
Default
AfpSize.MEDIUM |
|
||||||||||
value
|
Value of the input element.
Type
number | string | undefined
Default
undefined |
Methods
Learn more about using methods.
| Name | Description | Arguments |
|---|---|---|
doFocus
|
Focus the checkbox input
|
- |
doBlur
|
Blur the checkbox input
|
- |
doClick
|
Click the checkbox input
|
- |
Events
Learn more about events.
| Name | Return | Description |
|---|---|---|
afp-value-changed
|
{ value: number | string | undefined; checked: boolean }
|
Emitted when the checkbox value changes.
|
afp-change
|
boolean
|
Emitted when the checked state changes.
|
afp-focus
|
void
|
Emitted when the checkbox gains focus.
|
afp-blur
|
void
|
Emitted when the checkbox loses focus.
|
Slots
Learn more about slots.
| Name | Description |
|---|---|
default
|
The default slot for the label text.
|
checked-icon
|
The icon to display when the checkbox is checked.
|
indeterminate-icon
|
The icon to display when the checkbox is in an indeterminate state.
|
Internationalization
Learn more about internationalization.
| Key | Description |
|---|---|
checkbox.aria-label
|
The default `aria-label` text for checkbox.
|
CSS Parts
Learn more about CSS Parts.
| Name | Description | Selector |
|---|---|---|
wrapper
|
The wrapper element around the checkbox.
|
::part(wrapper)
|
base
|
The main label element that contains the checkbox input and visual.
|
::part(base)
|
input
|
The native checkbox input element.
|
::part(input)
|
visual
|
The visual representation of the checkbox.
|
::part(visual)
|
checked-icon
|
The icon displayed when the checkbox is checked.
|
::part(checked-icon)
|
indeterminate-icon
|
The icon displayed when the checkbox is in an indeterminate state.
|
::part(indeterminate-icon)
|
label
|
The label text element.
|
::part(label)
|
invalid
|
The error message element displayed when the checkbox is in an invalid state.
|
::part(invalid)
|
hint
|
The hint text element displayed below the checkbox.
|
::part(hint)
|
CSS Custom Properties
| Name | Description | Default |
|---|---|---|
--afp-checkbox-field-disabled-opacity
|
The opacity applied to the checkbox when it is disabled.
|
0.5
|
--afp-checkbox-label-disabled-opacity
|
The opacity applied to the checkbox label when it is disabled.
|
0.5
|
--afp-checkbox-background
|
The background color of the checkbox.
|
--afp-color-neutral-fill-loud
|
--afp-checkbox-color
|
The border color of a regular checkbox.
|
--afp-color-neutral-text-loud
|
--afp-input-error-border-color
|
The border color of the checkbox in the invalid/error state.
|
--afp-color-error-500
|
Dependencies
The component automatically brings in the listed items, including any nested dependencies that may exist.
Importing
Using the bundle is the recommended method to include components. If you’d rather handle imports manually, you can use the code examples below.
import '@afp-design-system/core/dist/components/checkbox/checkbox.js';