Skip to content

Checkbox API Reference

Props

PropTypeDefaultDescription
sizeString'md'Visual size. Options: 'xs', 'sm', 'md', 'lg', 'xl'.
disabledBooleanfalseDisables user interaction and lowers opacity.
readonlyBooleanfalsePrevents changes while keeping the default appearance.
labelString''Text displayed by the default label slot.
valueString/Number/BooleanRequiredPrimitive value emitted when toggled.
modelValueArray[]Main two-way binding (use v-model) containing the selected values array.
selectedArray[]Optional controlled array; used when modelValue is not provided.
valueComparatorFunction(array, value) => Array.isArray(array) && array.includes(value)Custom comparator for complex data structures.
variantString'default'Visual variant class (e.g. 'default', 'success').
allItemsArray[]Full dataset leveraged when a checkbox acts as a “Select All” control.
valueKeyString''Property name to read from allItems objects to derive primitive values.

Events

EventPayloadDescription
update:modelValuenewValuesEmitted with the updated array whenever the selection changes.
changenewValues, toggledValue, eventFires alongside update:modelValue and passes the toggled value plus the original DOM event.

Slots

SlotPropsDescription
icon{ isChecked }Replaces the default checkbox icon.
label{ isChecked }Custom label content.

Methods

The component doesn't expose any methods via template refs.

Example Usage

Basic Usage

vue
<template>
  <OCheckbox v-model="selected" label="Subscribe to updates" value="updates" />
</template>

<script setup>
import { ref } from "vue";
import { OCheckbox } from "your-component-library";

const selected = ref([]);
</script>

Checkbox Group

vue
<template>
  <div class="checkbox-group">
    <OCheckbox
      v-for="option in options"
      :key="option.value"
      v-model="selectedOptions"
      :label="option.label"
      :value="option.value"
      size="md"
    />
  </div>

  <div>Selected: {{ selectedOptions.join(", ") }}</div>
</template>

<script setup>
import { ref } from "vue";
import { OCheckbox } from "your-component-library";

const options = [
  { label: "Email", value: "email" },
  { label: "SMS", value: "sms" },
  { label: "Push", value: "push" },
];

const selectedOptions = ref([]);
</script>

Select All Toggle

vue
<template>
  <div class="select-all-demo">
    <OCheckbox
      v-model="selectedIds"
      label="Select All"
      value="selectAll"
      :allItems="items"
      valueKey="id"
    />

    <OCheckbox
      v-for="item in items"
      :key="item.id"
      v-model="selectedIds"
      :label="item.name"
      :value="item.id"
    />

    <div>Selected IDs: {{ selectedIds.join(", ") }}</div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { OCheckbox } from "your-component-library";

const items = [
  { id: 1, name: "Item 1" },
  { id: 2, name: "Item 2" },
  { id: 3, name: "Item 3" },
];

const selectedIds = ref([]);
</script>