Permits user to make one or more selections from a list
Default and standard spacing for checkboxes.
Different sizing for checkboxes.
Use a custom value in place of true/false checked state.
Use an array as the model to track a list of custom values.
Pass checkbox data into change handlers.
Displays status for checkbox group by indicating that some of the sub-selections in a list are selected. Provides user with ability to select or unselect all items in the list’s sub-group.
Note the usage of aria-controls
, id
, role
, aria-label
, and aria-labelledby
.
Custom styles for checkboxes.
Render a checkbox group with validation and error state
Many WCAG requirements are contextual to their implementation. To ensure that usage of this component complies with accessibility guidelines you are responsible for the following:
CdrFormGroup
should be:
label
property or slotCdrFormGroup
This component has compliance with WCAG guidelines by:
For more information, review techniques and failures for:
When using checkboxes in a list:
Checkbox labels should:
Checkboxes work independently from each other:
This component will bind any attribute that a native HTML checkbox element (opens new window) accepts.
labelClass
name
string
type
N/A
default
Adds CSS class to the label for custom styles.
inputClass
name
string
type
N/A
default
Adds CSS class to the input for custom styles.
contentClass
name
string
type
N/A
default
Adds CSS class to the slot wrapper for custom styles.
indeterminate
name
boolean
type
false
default
Shows checkbox in indeterminate state. This is a visual-only state with no logic for when to show it.
trueValue
name
string, number, boolean, object, array, symbol, function
type
true
default
The value when checked.
falseValue
name
string, number, boolean, object, array, symbol, function
type
false
default
The value when unchecked.
customValue
name
string, number, boolean, object, array, symbol, function
type
false
default
The value when used in a checkbox group. Replaces `trueValue` and `falseValue`.
modifier
name
string
type
N/A
default
Modifies the style variant for this component. Possible values: { ‘hide-figure’ }
size
name
string
type
'medium'
default
Sets the checkbox size; values can target responsive breakpoints. Breakpoint values are: xs, sm, md, and lg. Examples: { 'small' | 'medium' | 'large' | 'large@sm' }
Find more information about using Slots in the article Installing Cedar.
default
name
Sets the innerHTML for CdrCheckbox. This is the readable text for the <label> element.
change
name
newValue, event
arguments
$emit event fired on check/uncheck.
The CdrCheckbox component requires v-model
to track :checked
values.
This example uses true-value
and false-value
props to change what’s saved to the model.
<template>
<cdr-checkbox
v-model="model"
true-value="checked"
false-value="unchecked"
>
Option 1
</cdr-checkbox>
</template>
Use custom-value
with a shared model to create a checkbox group that will track multiple checkbox values.
<template>
<cdr-checkbox
v-model="groupModel"
:custom-value="{ value: ‘D’ }"
>
Option 1
</cdr-checkbox>
<cdr-checkbox
v-model="groupModel"
:custom-value="[ 9, 10 ]"
>
Option 2
</cdr-checkbox>
</template>
If both values are checked, the model would be [ { value: ‘D’ }, [ 9, 10 ] ]
. Unchecking either checkbox would remove its value from the model array.
Default checkbox to checked/unchecked state by setting the model in Javascript.
<template>
<cdr-checkbox
v-model="groupModel"
:custom-value="{ value: ‘D’ }"
>
Option 1
</cdr-checkbox>
...
</template>
<script>
...
data() {
return {
groupModel: [ { value: ‘D’ } ],
};
},
}
</script>
Set the indeterminate
prop to true
to generate an indeterminate checkbox, which looks different than the default. This is a visual styling only; it does not include any of the functional aspects of an indeterminate checkbox. To see a functioning example see the indeterminate example.
<template>
<cdr-checkbox
v-model="groupModel"
:indeterminate="true"
>
Option 1
</cdr-checkbox>
...
</template>
Following variants are available to the cdr-checkbox
modifier attribute:
Value | Description |
---|---|
'hide-figure' | Hides the checkbox icon |
Use the hide-figure
modifier to hide the checkbox itself, which leaves the text label as the clickable element. Add appropriate custom styles to convey selected and unselected states.
<template>
<cdr-checkbox
v-model="model"
name="model"
value="model"
modifier="hide-figure"
input-class="no-box"
content-class="no-box__content"
>
Add to cart
</cdr-checkbox>
</template>
<style>
.no-box:checked ~ .no-box__content {
color: green;
&::after {
content: '(checked)';
}
}
</style>