CheckboxGroup

A set of checklist buttons to select multiple option from a list.

Usage

Use the v-model directive to control the value of the CheckboxGroup or the default-value prop to set the initial value when you do not need to control its state.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
const value = ref(['System'])
</script>

<template>
  <PCheckboxGroup v-model="value" :items="items" />
</template>

Items

Use the items prop as an array of strings or numbers:

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
const value = ref(['System'])
</script>

<template>
  <PCheckboxGroup v-model="value" :items="items" />
</template>

You can also pass an array of objects with the following properties:

  • label?: string
  • description?: string
  • value?: string
  • disabled?: boolean
  • class?: any
  • pohon?: { item?: ClassNameValue, container?: ClassNameValue, base?: ClassNameValue, 'indicator'?: ClassNameValue, icon?: ClassNameValue, wrapper?: ClassNameValue, label?: ClassNameValue, description?: ClassNameValue }

This is the first option.

This is the second option.

This is the third option.

<script setup lang="ts">
import type { PCheckboxGroupItem } from 'pohon-ui'


const items = ref<PCheckboxGroupItem[]>([
  {
    label: 'System',
    description: 'This is the first option.',
    value: 'system'
  },
  {
    label: 'Light',
    description: 'This is the second option.',
    value: 'light'
  },
  {
    label: 'Dark',
    description: 'This is the third option.',
    value: 'dark'
  }
])
const value = ref([
  'system'
])
</script>

<template>
  <PCheckboxGroup v-model="value" :items="items" />
</template>
When using objects, you need to reference the value property of the object in the v-model directive or the default-value prop.

Value Key

You can change the property that is used to set the value by using the value-key prop. Defaults to value.

This is the first option.

This is the second option.

This is the third option.

<script setup lang="ts">
import type { PCheckboxGroupItem } from 'pohon-ui'


const items = ref<PCheckboxGroupItem[]>([
  {
    label: 'System',
    description: 'This is the first option.',
    id: 'system'
  },
  {
    label: 'Light',
    description: 'This is the second option.',
    id: 'light'
  },
  {
    label: 'Dark',
    description: 'This is the third option.',
    id: 'dark'
  }
])
const value = ref([
  'light'
])
</script>

<template>
  <PCheckboxGroup v-model="value" value-key="id" :items="items" />
</template>

Legend

Use the legend prop to set the legend of the CheckboxGroup.

Theme
<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup legend="Theme" :default-value="['System']" :items="items" />
</template>

Color

Use the color prop to change the color of the CheckboxGroup.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup color="neutral" :default-value="['System']" :items="items" />
</template>

Variant

Use the variant prop to change the variant of the CheckboxGroup.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup color="primary" variant="card" :default-value="['System']" :items="items" />
</template>

Size

Use the size prop to change the size of the CheckboxGroup.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup size="xl" variant="list" :default-value="['System']" :items="items" />
</template>

Orientation

Use the orientation prop to change the orientation of the CheckboxGroup. Defaults to vertical.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup
    orientation="horizontal"
    variant="list"
    :default-value="['System']"
    :items="items"
  />
</template>

Indicator

Use the indicator prop to change the position or hide the indicator. Defaults to start.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup indicator="end" variant="card" :default-value="['System']" :items="items" />
</template>

Disabled

Use the disabled prop to disable the CheckboxGroup.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup disabled :default-value="['System']" :items="items" />
</template>

API

Props

Prop Default Type
as'div'any

The element or component this component should render as.

legend string
valueKey'value' VK

When items is an array of objects, select the field to use as the value.

labelKey'label' keyof Extract<NestedItem<T>, object> | DotPathKeys<Extract<NestedItem<T>, object>>

When items is an array of objects, select the field to use as the label.

descriptionKey'description' keyof Extract<NestedItem<T>, object> | DotPathKeys<Extract<NestedItem<T>, object>>

When items is an array of objects, select the field to use as the description.

items T
modelValue GetItemValue<T, VK, NestedItem<T>>[]

The controlled value of the CheckboxGroup. Can be bind as v-model.

defaultValue GetItemValue<T, VK, NestedItem<T>>[]

The value of the CheckboxGroup when initially rendered. Use when you do not need to control the state of the CheckboxGroup.

size'md' "md" | "xs" | "sm" | "lg" | "xl"
variant'list' "list" | "card" | "table"
orientation'vertical' "horizontal" | "vertical"

The orientation the checkbox buttons are laid out.

disabledboolean

When true, prevents the user from interacting with the checkboxes

loopfalseboolean

Whether keyboard navigation should loop around

name string

The name of the field. Submitted with its owning form as part of a name/value pair.

requiredboolean

When true, indicates that the user must set the value before the owning form can be submitted.

color'primary' "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral"
indicator'start' "start" | "end" | "hidden"

Position of the indicator.

iconappConfig.pohon.icons.check string | object

The icon displayed when checked.

pohon { root?: ClassValue; fieldset?: ClassValue; legend?: ClassValue; item?: ClassValue; } & { root?: ClassValue; container?: ClassValue; base?: ClassValue; indicator?: ClassValue; icon?: ClassValue; wrapper?: ClassValue; label?: ClassValue; description?: ClassValue; }

Slots

Slot Type
legendobject
label{ item: T[number] & { id: string; }; }
description{ item: T[number] & { id: string; }; }

Emits

Event Type
update:modelValue[value: T[number][]]
change[event: Event]

Theme

We use unocss-variants to customize the theme. Read more about it in the theming guide.

Below is the theme configuration skeleton for the PCheckboxGroup. Since the component is provided unstyled by default, you will need to fill in these values to apply your own custom look and feel. If you prefer to use our pre-built, opinionated styling, you can instead use our UnoCSS preset, this docs is using it as well.

app.config.ts
export default defineAppConfig({
  pohon: {
    checkboxGroup: {
      slots: {
        root: '',
        fieldset: '',
        legend: '',
        item: ''
      },
      variants: {
        orientation: {
          horizontal: {
            fieldset: ''
          },
          vertical: {
            fieldset: ''
          }
        },
        color: {
          primary: {},
          secondary: {},
          success: {},
          info: {},
          warning: {},
          error: {},
          neutral: {}
        },
        variant: {
          list: {},
          card: {},
          table: {
            item: ''
          }
        },
        size: {
          xs: {
            fieldset: '',
            legend: ''
          },
          sm: {
            fieldset: '',
            legend: ''
          },
          md: {
            fieldset: '',
            legend: ''
          },
          lg: {
            fieldset: '',
            legend: ''
          },
          xl: {
            fieldset: '',
            legend: ''
          }
        },
        required: {
          true: {
            legend: ''
          }
        },
        disabled: {
          true: {}
        }
      },
      compoundVariants: [],
      defaultVariants: {
        size: 'md',
        variant: 'list',
        color: 'primary'
      }
    }
  }
};
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import pohon from 'pohon-ui/vite'

export default defineAppConfig({
  pohon: {
    checkboxGroup: {
      slots: {
        root: '',
        fieldset: '',
        legend: '',
        item: ''
      },
      variants: {
        orientation: {
          horizontal: {
            fieldset: ''
          },
          vertical: {
            fieldset: ''
          }
        },
        color: {
          primary: {},
          secondary: {},
          success: {},
          info: {},
          warning: {},
          error: {},
          neutral: {}
        },
        variant: {
          list: {},
          card: {},
          table: {
            item: ''
          }
        },
        size: {
          xs: {
            fieldset: '',
            legend: ''
          },
          sm: {
            fieldset: '',
            legend: ''
          },
          md: {
            fieldset: '',
            legend: ''
          },
          lg: {
            fieldset: '',
            legend: ''
          },
          xl: {
            fieldset: '',
            legend: ''
          }
        },
        required: {
          true: {
            legend: ''
          }
        },
        disabled: {
          true: {}
        }
      },
      compoundVariants: [],
      defaultVariants: {
        size: 'md',
        variant: 'list',
        color: 'primary'
      }
    }
  }
};

Changelog

No recent changes