Skip to content
On this page

Radop Group

Single selection among multiple options.

Basic Usage

Bind v-model

<template>
  <HcRadioGroup
    v-model="value"
    label="Label text"
    :items="items"
  />
</template>

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

const value = ref('');

const items = ref<RadioItemType[]>([
  {
    value: 'option_1',
    label: 'Option 1',
  },
  {
    value: 'option_2',
    label: 'Option 2',
    disabled: true,
  },
  {
    value: 'option_3',
    label: 'Option 3',
  },
  {
    value: 'option_4',
    label: 'Option 4',
  },
  {
    value: 'option_5',
    label: 'Option 5',
  },
]);
</script>

Direction

Change prop direction to determinate radio group align

<template>
  <HcRadioGroup
    v-model="value"
    label="Label"
    :items="items"
    direction="col"
  />
</template>

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

const value = ref('');

const items = ref<RadioItemType[]>([
  {
    value: 'option_1',
    label: 'Option 1',
  },
  {
    value: 'option_2',
    label: 'Option 2',
  },
  {
    value: 'option_3',
    label: 'Option 3',
  },
]);
</script>

Column amount

Use prop cols together with direction="col" to determinate amount of cols

<template>
  <HcRadioGroup
    v-model="value"
    label="Label"
    :items="items"
    direction="col"
    :cols="3"
  />
</template>

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

const value = ref('');

const items = ref<RadioItemType[]>([
  {
    value: 'option_1',
    label: 'Option 1',
  },
  {
    value: 'option_2',
    label: 'Option 2',
  },
  {
    value: 'option_3',
    label: 'Option 3',
  },
  {
    value: 'option_4',
    label: 'Option 4',
  },
  {
    value: 'option_5',
    label: 'Option 5',
  },
  {
    value: 'option_6',
    label: 'Option 6',
  },
]);

</script>

Disabled & Readonly

Use prop disabled or readonly to change state

<template>
  <div class="grid grid-cols-2 gap-6">
    <HcRadioGroup
      v-model="value1"
      :items="items"
      label="Disabled"
      direction="col"
      disabled
    />

    <HcRadioGroup
      v-model="value2"
      :items="items"
      label="Readonly"
      direction="col"
      readonly
    />
  </div>
</template>

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

const value1 = ref('');
const value2 = ref('');

const items = ref<RadioItemType[]>([
  {
    value: 'option_1',
    label: 'Option 1',
  },
  {
    value: 'option_2',
    label: 'Option 2',
  },
  {
    value: 'option_3',
    label: 'Option 3',
  },
  {
    value: 'option_4',
    label: 'Option 4',
  },
]);

</script>

Error message

Add prop errorMsg for show error message and change state to error

<template>
  <div>
    <HcRadioGroup
      v-model="value"
      label="Label"
      :items="items"
      error-msg="This field is required"
    />
  </div>
</template>

<script lang="ts" setup>
import { RadioItemType, HcRadioGroup } from '@deeepvision/hope-component-kit';

import { ref } from 'vue';

const value = ref('');

const items = ref<RadioItemType[]>([
  {
    value: 'option_1',
    label: 'Option 1',
  },
  {
    value: 'option_2',
    label: 'Option 2',
  },
  {
    value: 'option_3',
    label: 'Option 3',
  },
  {
    value: 'option_4',
    label: 'Option 4',
  },
  {
    value: 'option_5',
    label: 'Option 5',
  },
]);
</script>

Props

PropertyType Values Description Default
modelValueStringStringbinding value
itemsRadioItemType[]RadioItemType[]items of radio group[]
labelStringStringlabel text
nameStringStringnative 'name' attribute
directionStringrowcoldirection of the radio grouprow
colsNumberNumberif direction is col, amount of cols1
customClassStringStringcustom class for each radio item1
errorMsStringStringerror message
disabledBooleanBooleanwhether component is disabledfalse
readonlyBooleanBooleanwhether component is read onlyfalse

Slots

PropertyType Values Description Default
label-suffix-Customize label suffix
default-Add your content under radio group items

Events

PropertyType Values Description Default
update:model-valueFunctionvalue - string | numbertriggers when the bound value changes
deleteFunctionvalue - string | numbertriggers when the bound value changes

Created by DeepVision Software.