Skip to content
On this page

Checkbox

A checkbox in its simplest form provides a toggle between 2 values.

Checkbox Basic Usage

Bind v-model to a Boolean typed variable.

<template>
  <div class="flex justify-between items-end">
    <HcCheckbox
      v-model="checked"
      label="Checkbox"
    />
  </div>
</template>

<script lang="ts" setup>
import { HcCheckbox } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';

const checked = ref(false);
</script>

Checkbox States

Checkbox can have different states such as disabled, readonly and indeterminate.

<template>
  <div class="flex flex-col">
    <HcCheckbox
      v-model="value1"
      label="Disabled checked"
      disabled
    />

    <HcCheckbox
      v-model="value2"
      label="Disabled unchecked"
      disabled
      class="mt-4"
    />

    <HcCheckbox
      v-model="value3"
      label="Readonly checked"
      readonly
      class="mt-4"
    />

    <HcCheckbox
      v-model="value4"
      label="Readonly unchecked"
      readonly
      class="mt-4"
    />

    <HcCheckbox
      v-model="value5"
      label="Indeterminate"
      indeterminate
      class="mt-4"
    />
  </div>
</template>

<script lang="ts" setup>
import { HcCheckbox } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';

const value1 = ref(true);
const value2 = ref(false);
const value3 = ref(true);
const value4 = ref(true);
const value5 = ref(true);
</script>

Error Usage

Add Boolean prop error or prop errorMsg for show error state

This field is required
<template>
  <div class="flex flex-col">
    <HcCheckbox
      v-model="value1"
      label="Checkbox 1"
      error
    />

    <HcCheckbox
      v-model="value2"
      label="Checkbox 2"
      :error-msg="!value2 ? 'This field is required' : ''"
      class="mt-4"
    />
  </div>
</template>

<script lang="ts" setup>
import { HcCheckbox } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';

const value1 = ref(false);
const value2 = ref(false);
</script>

Props

PropertyType Values Description Default
modelValueBooleanBooleanbinding valuefalse
labelStringStringlabel text
disabledBooleanBooleanwhether component is disabledfalse
errorBooleanBooleandetermine if the component has error and change its style to that state.false
errorMsgStringStringerror message
indeterminateBooleanBooleansame as indeterminate in native checkboxfalse
readonlyBooleanBooleanwhether component is read onlyfalse
idStringStringnative 'id' attribute
nameStringStringnative 'name' attribute

Slots

PropertyType Values Description Default
left-slot-customize left content
default-customize label content

Events

PropertyType Values Description Default
update:model-valueFunctionvalue - booleantriggers when the binding value changes
changeFunctionvalue - booleantriggers when the binding value changes
blurFunctionevt - FocusEventtriggers when checkbox blurs

Created by DeepVision Software.