<script setup lang="ts">
import { ACheckboxIndicator, ACheckboxRoot } from 'akar';
import { ref } from 'vue';
const checkboxOne = ref(true);
</script>
<template>
<div class="flex flex-row items-start relative">
<div class="flex h-5 items-center">
<ACheckboxRoot
v-model="checkboxOne"
class="rounded-sm size-4 ring ring-ring-accented ring-inset overflow-hidden focus-visible:(outline-2 outline-primary outline-offset-2)"
>
<ACheckboxIndicator class="color-text-inverted bg-primary flex size-full items-center justify-center">
<i
class="i-lucide:check shrink-0 size-full"
/>
</ACheckboxIndicator>
</ACheckboxRoot>
</div>
<div class="text-sm ms-2 w-full">
<label class="color-text font-medium block">
Accept terms and conditions.
</label>
</div>
</div>
</template>
Import all parts and piece them together.
<script setup>
import { ACheckboxGroupRoot, ACheckboxIndicator, ACheckboxRoot } from 'akar';
</script>
<template>
<ACheckboxRoot>
<ACheckboxIndicator />
</ACheckboxRoot>
<!-- or with array support -->
<ACheckboxGroupRoot>
<ACheckboxRoot>
<ACheckboxIndicator />
</ACheckboxRoot>
</ACheckboxGroupRoot>
</template>
One benefit of using Akar is its flexibility and low-level control over the components. However, this also means that you may need to manually construct more complex UI elements by combining multiple Akar components together.
If you feel there's a lot of elements that needs to be constructed manually using Akar, consider using Pohon UI instead. It provides a higher-level abstraction over Akar components with pre-defined styles and behaviors that can help you build UIs faster.
Contains all the parts of a checkbox. An input will also render when used within a form to ensure events propagate correctly.
| Prop | Default | Type |
|---|---|---|
as | 'button' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
defaultValue | boolean | 'indeterminate'The value of the checkbox when it is initially rendered. Use when you do not need to control its value. | |
disabled | booleanWhen | |
id | stringId of the element | |
modelValue | boolean | 'indeterminate' | null | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
required | booleanWhen | |
value | 'on' | AcceptableValueThe value given as data when submitted with a |
| Event | Type |
|---|---|
update:modelValue | [value: boolean | 'indeterminate']Event handler called when the value of the checkbox changes. |
| Slot | Type |
|---|---|
modelValue | false | true | 'indeterminate'The controlled value of the checkbox. Can be binded with v-model. |
state | CheckboxCheckedStateCurrent state |
| Attribute | Value |
|---|---|
[data-state] | 'checked' | 'unchecked' | 'indeterminate' |
[data-disabled] | Present when disabled |
Renders when the checkbox is in a checked or indeterminate state. You can style this element directly, or you can use it as a wrapper to put an icon into, or both.
| Prop | Default | Type |
|---|---|---|
as | 'span' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
forceMount | booleanUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. |
| Attribute | Value |
|---|---|
[data-state] | 'checked' | 'unchecked' | 'indeterminate' |
[data-disabled] | Present when disabled |
Wrapper around CheckboxRoot to support array of modelValue
| Prop | Default | Type |
|---|---|---|
as | 'div' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
defaultValue | AcceptableValue[]The value of the checkbox when it is initially rendered. Use when you do not need to control its value. | |
dir | 'ltr' | 'rtl'The direction of navigation between items. | |
disabled | booleanWhen | |
loop | booleanWhether keyboard navigation should loop around | |
modelValue | AcceptableValue[]The controlled value of the checkbox. Can be binded with v-model. | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
orientation | 'horizontal' | 'vertical'The orientation of the group. Mainly so arrow navigation is done accordingly (left & right vs. up & down) | |
required | booleanWhen | |
rovingFocus | true | booleanWhen |
| Event | Type |
|---|---|
update:modelValue | [value: AcceptableValue[]]Event handler called when the value of the checkbox changes. |
You can set the checkbox to indeterminate by taking control of its state.
<script setup>
import { Icon } from '@iconify/vue';
import { ACheckboxIndicator, ACheckboxRoot } from 'akar';
const checked = ref('indeterminate');
</script>
<template>
<ACheckboxRoot v-model="checked">
<ACheckboxIndicator>
<Icon
v-if="checked === 'indeterminate'"
icon="radix-icons:divider-horizontal"
/>
<Icon
v-if="checked"
icon="radix-icons:check"
/>
</ACheckboxIndicator>
</ACheckboxRoot>
<button
type="button"
@click="() => (checked === 'indeterminate' ? (checked = false) : (checked = 'indeterminate'))"
>
Toggle indeterminate
</button>
</template>
Adheres to the tri-state Checkbox WAI-ARIA design pattern.
| Key | Description |
|---|---|
Space | Checks/unchecks the checkbox |