Form Checkbox

For cross browser consistency, BFormCheckboxGroup and BFormCheckbox use Bootstrap's custom checkbox input to replace the browser default checkbox input. It is built on top of semantic and accessible markup, so it is a solid replacement for the default checkbox input.

Single checkbox

State: false
HTML
vue
<template>
  <div>
    <BFormCheckbox
      id="checkbox-1"
      v-model="status"
      name="checkbox-1"
      value="accepted"
      unchecked-value="not_accepted"
    >
      I accept the terms and use
    </BFormCheckbox>

    <div>
      State: <strong>{{ status }}</strong>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
const status = ref(false)
</script>

Multiple choice checkboxes

Using options array:
Using sub-components:
Selected: []
HTML
vue
<template>
  <div>
    <b-form-group
      v-slot="{ariaDescribedby}"
      label="Using options array:"
    >
      <b-form-checkbox-group
        id="checkbox-group-1"
        v-model="selected"
        :options="options"
        :aria-describedby="ariaDescribedby"
        name="flavour-1"
      />
    </b-form-group>

    <b-form-group
      v-slot="{ariaDescribedby}"
      label="Using sub-components:"
    >
      <b-form-checkbox-group
        id="checkbox-group-2"
        v-model="selected"
        :aria-describedby="ariaDescribedby"
        name="flavour-2"
      >
        <b-form-checkbox value="orange">Orange</b-form-checkbox>
        <b-form-checkbox value="apple">Apple</b-form-checkbox>
        <b-form-checkbox value="pineapple">Pineapple</b-form-checkbox>
        <b-form-checkbox value="grape">Grape</b-form-checkbox>
      </b-form-checkbox-group>
    </b-form-group>

    <div>
      Selected: <strong>{{ selected }}</strong>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const selected = ref([])

const options = [
  {text: 'Orange', value: 'orange'},
  {text: 'Apple', value: 'apple'},
  {text: 'Pineapple', value: 'pineapple'},
  {text: 'Grape', value: 'grape'},
]
</script>

Options property

options can be an array of strings or objects, or a key-value object. Available fields:

  • value The selected value which will be set on v-model
  • disabled Disables item for selection
  • text Display text

value can be a string, number, or simple object. Avoid using complex types in values.

NOTE

The BootstrapVue field html on the options object has been deprecated. See our Migration Guide for details.

Options as an array

ts
const options = ['A', 'B', 'C', {text: 'D', value: {d: 1}, disabled: true}, 'E', 'F']

If an array entry is a string, it will be used for both the generated value and text fields.

You can mix using strings and objects in the array.

Internally, BootstrapVueNext will convert the above array to the following array (the array of objects) format:

ts
const options = [
  {text: 'A', value: 'A', disabled: false},
  {text: 'B', value: 'B', disabled: false},
  {text: 'C', value: 'C', disabled: false},
  {text: 'D', value: {d: 1}, disabled: true},
  {text: 'E', value: 'E', disabled: false},
  {text: 'F', value: 'F', disabled: false},
]

Options as an array of objects

ts
const options = [
  {text: 'Item 1', value: 'first'},
  {text: 'Item 2', value: 'second'},
  {text: 'Item 3', value: 'third', disabled: true},
  {text: 'Item 4'},
  {text: 'Item 5', value: {foo: 'bar', baz: true}},
]

If value is missing, then text will be used as both the value and text fields.

Internally, BootstrapVueNext will convert the above array to the following array (the array of objects) format:

ts
const options = [
  {text: 'Item 1', value: 'first', disabled: false},
  {text: 'Item 2', value: 'second', disabled: false},
  {text: 'Item 3', value: 'third', disabled: true},
  {text: 'Item 4', value: 'Item 4', disabled: false},
  {text: 'Item 5', value: 'E', disabled: false},
]

Changing the option field names

If you want to customize the field property names (for example using name field for display text) you can easily change them by setting the text-field, value-field, and disabled-field props to a string that contains the property name you would like to use:

Selected: [ "A" ]
HTML
vue
<template>
  <BFormCheckboxGroup
    v-model="checked"
    :options="options"
    class="mb-3"
    value-field="item"
    text-field="name"
    disabled-field="notEnabled"
  />
  <div class="mt-3">
    Selected: <strong>{{ checked }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
const checked = ref(['A'])

const options = [
  {item: 'A', name: 'Option A'},
  {item: 'B', name: 'Option B'},
  {item: 'D', name: 'Option C', notEnabled: true},
  {item: {d: 1}, name: 'Option D'},
]
</script>

Checkbox values and v-model

By default, BFormCheckbox value will be true when checked and false when unchecked. You can customize the checked and unchecked values by specifying the value and unchecked-value properties, respectively.

When you have multiple checkboxes that bind to a single data state variable, you must provide an array reference ([ ]) to your v-model.

Note that when v-model is bound to multiple checkboxes (i.e an array ref), the unchecked-value is not used. Only the value(s) of the checked checkboxes will be returned in the v-model bound array. You should provide a unique value for each checkbox's value prop (the default of true will not work when bound to an array).

To pre-check any checkboxes, set the v-model to the value(s) of the checks that you would like pre-selected.

When placing individual BFormCheckbox components within a BFormCheckboxGroup, most props and the v-model are inherited from the BFormCheckboxGroup.

NOTE

The unchecked-value prop does not affect the native <input>'s value attribute, because browsers do not include unchecked boxes in form submissions. To guarantee that one of two values is submitted in a native <form> submit (e.g. 'yes' or 'no'), use radio inputs instead. This is the same limitation that Vue has with native checkbox inputs.

Selected:
HTML
vue
<template>
  <BFormCheckbox
    v-for="(car, index) in availableCars"
    :key="index"
    v-model="selectedCars"
    :value="car"
  >
    {{ car }}
  </BFormCheckbox>

  Selected: <strong>{{ concatSelectedCars }}</strong>
</template>

<script setup lang="ts">
import {computed, ref} from 'vue'

const availableCars = ['BMW', 'Mercedes', 'Toyota']
const selectedCars = ref([])

const concatSelectedCars = computed(() => selectedCars.value.join(', '))
</script>

Multiple checkboxes and accessibility

When binding multiple checkboxes together, you must set the name prop to the same value for all BFormCheckboxs in the group individually. This will inform users of assistive technologies that the checkboxes are related and enables native browser keyboard navigation.

Whenever using multiple checkboxes, it is recommended that the checkboxes be placed in a BFormGroup component to associate a label with the entire group of checkboxes. See examples above.

Inline and stacked checkboxes

BFormCheckboxGroup components render inline checkboxes by default, while BFormCheckbox renders block-level (stacked) checkboxes.

Set the prop stacked on BFormCheckboxGroup to place each form control one over the other, or if using individual checkboxes not inside a BFormCheckboxGroup, set the inline prop on BFormCheckbox.

HTML
vue
<template>
  <div class="my-2">
    <label>Form-checkbox-group inline checkboxes (default)</label>
  </div>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    name="flavour-1a"
  />

  <div class="my-2">
    <label>Form-checkbox-group stacked checkboxes</label>
  </div>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    name="flavour-2a"
    stacked
  />

  <div class="my-2">
    <label>Individual stacked checkboxes (default)</label>
  </div>

  <BFormCheckbox
    v-for="option in options"
    :key="option.value"
    v-model="selected"
    :value="option.value"
    name="flavour-3a"
  >
    {{ option.text }}
  </BFormCheckbox>

  <div class="my-2">
    <label>Individual inline checkboxes</label>
  </div>

  <BFormCheckbox
    v-for="option in options"
    :key="option.value"
    v-model="selected"
    :value="option.value"
    name="flavour-4a"
    inline
  >
    {{ option.text }}
  </BFormCheckbox>
</template>

<script setup lang="ts">
import {ref} from 'vue'
const selected = ref(['A'])

const options = [
  {text: 'Orange', value: 'orange'},
  {text: 'Apple', value: 'apple'},
  {text: 'Pineapple', value: 'pineapple'},
  {text: 'Grape', value: 'grape'},
]
</script>

Control sizing

Use the size prop to control the size of the checkbox. The default size is medium. Supported size values are sm (small) and lg (large).

HTML
template
<BFormCheckbox size="sm">Small</BFormCheckbox>
<BFormCheckbox>Default</BFormCheckbox>
<BFormCheckbox size="lg">Large</BFormCheckbox>

Reverse

Use the reverse prop to put your checkboxes and switches on the opposite side of the label.

HTML
template
<BFormCheckbox reverse>Reverse checkbox</BFormCheckbox>
<BFormCheckbox
  reverse
  disabled
  >Disabled reverse checkbox</BFormCheckbox
>
<BFormCheckbox
  reverse
  switch
  >Reverse switch ceckbox input</BFormCheckbox
>

Without Labels

In order to omit labels as described in the bootstrap documentation just leave the default slot empty. Remember to still provide some form of accessible name for assistive technologies (for instance, using aria-label).

HTML
template
<BFormCheckbox />
<BFormCheckbox disabled />
<BFormCheckbox switch />

Button style checkboxes

You can optionally render checkboxes to appear as buttons, either individually, or in a group.

Button style checkboxes will have the class .active automatically applied to the label when they are in the checked state.

Individual checkbox button style

A single checkbox can be rendered with a button appearance by setting the prop button to true.

Change the button variant by setting the button-variant prop to one of the standard Bootstrap button variants (see BButton for supported variants). The default variant is secondary.

HTML
vue
<template>
  <div class="hstack gap-3">
    <BFormCheckbox
      v-model="button1Checked"
      button
    >
      Button Checkbox (Checked: {{ button1Checked }})
    </BFormCheckbox>

    <BFormCheckbox
      v-model="button2Checked"
      button
      button-variant="danger"
    >
      Button Checkbox (Checked: {{ button2Checked }})
    </BFormCheckbox>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const button1Checked = ref(false)
const button2Checked = ref(false)
</script>

Grouped button style checkboxes

Render groups of checkboxes with the look of a button-group by setting the prop buttons on BFormCheckboxGroup. Change the button variant by setting the button-variant prop to one of the standard Bootstrap button variants (see BButton for supported variants). The default button-variant is secondary.

HTML
vue
<template>
  <div class="my-2">
    <label>Form-checkbox-group inline checkboxes (default)</label>
  </div>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    name="buttons-1"
    buttons
  />

  <div class="my-2">
    <label>Button-group style checkboxes with variant primary and large buttons</label>
  </div>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    buttons
    button-variant="primary"
    size="lg"
    name="buttons-2"
  />

  <div class="my-2">
    <label>Stacked (vertical) button-group style checkboxes</label>
  </div>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    stacked
    buttons
  />
</template>

<script setup lang="ts">
import {ref} from 'vue'

const selected = ref(['A'])

const options = [
  {text: 'Orange', value: 'orange'},
  {text: 'Apple', value: 'apple'},
  {text: 'Pineapple', value: 'pineapple'},
  {text: 'Grape', value: 'grape'},
]
</script>

Switch style checkboxes

Switch styling is supported on BFormCheckbox and BFormCheckboxGroup components.

NOTE

If the checkbox is in button mode, switch mode will have no effect.

Individual checkbox switch style

A single checkbox can be rendered with a switch appearance by setting the prop switch to true.

HTML
vue
<template>
  <BFormCheckbox
    v-model="switchChecked"
    switch
  >
    Switch Checkbox <strong>(Checked: {{ switchChecked }})</strong>
  </BFormCheckbox>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const switchChecked = ref(false)
</script>

Grouped switch style checkboxes

Render groups of checkboxes with the look of a switches by setting the prop switches on BFormCheckboxGroup.

HTML
vue
<template>
  <div class="my-2">
    <label>Inline switch style checkboxes</label>
  </div>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    switches
  />

  <div class="my-2">
    <label>Stacked (vertical) switch style checkboxes</label>
  </div>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    switches
    stacked
  />
</template>

<script setup lang="ts">
import {ref} from 'vue'

const selected = ref([])

const options = [
  {text: 'Red', value: 'red'},
  {text: 'Green', value: 'green'},
  {text: 'Yellow (disabled)', value: 'yellow', disabled: true},
  {text: 'Blue', value: 'blue'},
]
</script>

Switch sizing

Use the size prop to control the size of the switch. The default size is medium. Supported size values are sm (small) and lg (large).

HTML
template
<BFormCheckbox
  switch
  size="sm"
  >Small</BFormCheckbox
>
<BFormCheckbox switch>Default</BFormCheckbox>
<BFormCheckbox
  switch
  size="lg"
  >Large</BFormCheckbox
>

Sizes can be set on individual BFormCheckbox components, or inherited from the size setting of BFormCheckboxGroup.

NOTE

Bootstrap v5.x does not natively support sizes for the custom switch control. However, bootstrap-vue-next includes custom SCSS/CSS that adds support for sizing the custom switches.

Non-custom check inputs (plain)

You can have BFormCheckboxGroup or BFormCheckbox render a browser native checkbox input by setting the plain prop.

HTML
vue
<template>
  <div class="my-2">
    <label>Plain inline checkboxes</label>
  </div>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    plain
  />

  <div class="my-2">
    <label>Plain stacked checkboxes</label>
  </div>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    plain
    stacked
  />
</template>

<script setup lang="ts">
import {ref} from 'vue'

const selected = ref([])
const options = [
  {text: 'Red', value: 'red'},
  {text: 'Green', value: 'green'},
  {text: 'Yellow (disabled)', value: 'yellow', disabled: true},
  {text: 'Blue', value: 'blue'},
]
</script>

NOTE

The plain prop has no effect when button or buttons is set.

Contextual states

Bootstrap includes validation styles for valid and invalid states on most form controls.

Generally speaking, you'll want to use a particular state for specific types of feedback:

  • false (denotes invalid state) is great for when there is a blocking or required field. A user must fill in this field properly to submit the form
  • true (denotes valid state) is ideal for situations when you have per-field validation throughout a form and want to encourage a user through the rest of the fields
  • null Displays no validation state (neither valid nor invalid)

To apply one of the contextual state icons on BFormCheckbox, set the state prop to false (for invalid), true (for valid), or null (no validation state).

NOTE

Contextual states are not supported when in button mode.

Contextual state and validation example

Please select two
HTML
vue
<template>
  <BFormCheckbox :state="false">Checkbox state false</BFormCheckbox>
  <BFormCheckbox :state="true">Checkbox state true</BFormCheckbox>
  <BFormCheckbox>Checkbox state null</BFormCheckbox>

  <BFormCheckboxGroup
    v-model="selected"
    :options="options"
    :state="contextualState"
    name="checkbox-validation"
  />

  <div v-if="!contextualState">Please select two</div>
  <div v-if="contextualState">Thank you</div>
</template>

<script setup lang="ts">
import {computed, ref} from 'vue'

const options = [
  {text: 'First Check', value: 'first'},
  {text: 'Second Check', value: 'second'},
  {text: 'Third Check', value: 'third'},
]

const selected = ref([])

const contextualState = computed(() => selected.value.length === 2)
</script>

Required constraint

When using individual BFormCheckbox components (not in a BFormCheckboxGroup), and you want the checkbox(es) to be required in your form, you must provide a name on each BFormCheckbox in order for the required constraint to work. All BFormCheckbox components tied to the same v-model must have the same name.

The name is required in order for Assistive Technologies (such as screen readers, and keyboard only users) to know which checkboxes belong to the same form variable (the name also automatically enables native browser keyboard navigation), hence required will only work if name is set. BFormCheckboxGroup will automatically generate a unique input name if one is not provided on the group.

Autofocus

When the autofocus prop is set on BFormCheckbox, the input will be auto-focused when it is inserted (i.e. mounted) into the document, or re-activated when inside a Vue KeepAlive component. Note that this prop does not set the autofocus attribute on the input, nor can it tell when the input becomes visible.

Indeterminate (tri-state) support

Normally a checkbox input can only have two states: checked or unchecked. They can have any value, but they either submit that value (checked) or do not (unchecked) with a form submission (although BootstrapVueNext allows a value for the unchecked state on a single checkbox).

Visually, there are actually three states a checkbox can be in: checked, unchecked, or indeterminate.

The indeterminate state is visual only. The checkbox is still either checked or unchecked as a value. That means the visual indeterminate state masks the real value of the checkbox, so that better make sense in your UI!.

BFormCheckbox supports setting this visual indeterminate state via a secondary named model called indeterminate (defaults to undefined). Clicking the checkbox will clear the indeterminate state and emit an update:indeterminate=false event. To reset the state set v-model:indeterminate value to true.

Checked: true
Indeterminate: true
HTML
vue
<template>
  <BFormCheckbox
    v-model="checked"
    v-model:indeterminate="indeterminate"
    >Click me to see what happens</BFormCheckbox
  >
  <BButton
    class="mt-2"
    :disabled="indeterminate"
    @click="indeterminate = true"
    >Reset Indeterminate</BButton
  >
  <div class="mt-2">
    Checked: <strong>{{ checked }}</strong
    ><br />
    Indeterminate: <strong>{{ indeterminate }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const checked = ref(true)
const indeterminate = ref(true)
</script>

Indeterminate checkbox use-case example:

Choose your flavors:
Selected: []
All Selected: false
Indeterminate: false
HTML
vue
<template>
  <BFormGroup>
    <template #label>
      <b>Choose your flavors:</b><br />
      <BFormCheckbox
        v-model="allSelected"
        v-model:indeterminate="asIndeterminate"
        aria-describedby="flavors"
        aria-controls="flavors"
        @update:model-value="toggleAll"
      >
        {{ allSelected ? 'Un-select All' : 'Select All' }}
      </BFormCheckbox>
    </template>

    <template #default="{ariaDescribedby}">
      <BFormCheckboxGroup
        id="flavors"
        v-model="flavorSelected"
        :options="flavors"
        :aria-describedby="ariaDescribedby"
        name="flavors"
        class="ms-4"
        aria-label="Individual flavors"
        stacked
      />
    </template>
  </BFormGroup>

  <div>
    Selected: <strong>{{ flavorSelected }}</strong
    ><br />
    All Selected: <strong>{{ allSelected }}</strong
    ><br />
    Indeterminate: <strong>{{ asIndeterminate }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref, watch} from 'vue'
import type {CheckboxValue} from 'bootstrap-vue-next'

const flavors = ['Orange', 'Grape', 'Apple', 'Lime', 'Very Berry']
const flavorSelected = ref<string[]>([])
const allSelected = ref(false)
const asIndeterminate = ref(false)

const toggleAll = (checked?: CheckboxValue | CheckboxValue[]) => {
  flavorSelected.value = checked ? flavors.slice() : []
}

watch(flavorSelected, (newValue: string[]) => {
  // Handle changes in individual flavor checkboxes
  if (newValue.length === 0) {
    asIndeterminate.value = false
    allSelected.value = false
  } else if (newValue.length === flavors.length) {
    asIndeterminate.value = false
    allSelected.value = true
  } else {
    asIndeterminate.value = true
    allSelected.value = false
  }
})
</script>

TypeScript Type Safety

BFormCheckboxGroup provides full TypeScript type safety through generic type parameters. When you provide typed options, TypeScript will:

  1. Validate field names - Ensure value-field, text-field, and disabled-field props reference actual keys of your option type
  2. Infer v-model type - Automatically determine the correct type for v-model based on your value-field

Basic Type-Safe Usage

When using TypeScript, specify value-field, text-field, and disabled-field to leverage type safety:

Selected user IDs: [ 1, 4 ]
HTML
vue
<template>
  <!-- #region template -->
  <div>
    <BFormCheckboxGroup
      id="checkbox-type-safe-basic"
      v-model="selectedUsers"
      :options="users"
      value-field="id"
      text-field="name"
      disabled-field="inactive"
    />
    <div class="mt-3">
      Selected user IDs: <strong>{{ selectedUsers }}</strong>
    </div>
  </div>
  <!-- #endregion template -->
</template>

<script setup lang="ts">
import {ref} from 'vue'

interface User {
  id: number
  name: string
  inactive?: boolean
}

const users: User[] = [
  {id: 1, name: 'Alice'},
  {id: 2, name: 'Bob'},
  {id: 3, name: 'Charlie', inactive: true},
  {id: 4, name: 'David'},
]

// TypeScript knows selectedUsers is readonly number[]
const selectedUsers = ref<readonly number[]>([1, 4])
</script>

In this example, TypeScript knows that selectedIds is readonly number[] because the id field of User is typed as number.

Type-Safe Field Validation

TypeScript will catch errors when you use invalid field names:

Select users
Please select at least one user
Select one or more users
HTML
vue
<template>
  <!-- #region template -->
  <BFormGroup
    label="Select users"
    description="Select one or more users"
  >
    <BFormCheckboxGroup
      id="checkbox-type-safe-validation"
      v-model="selectedIds"
      :options="users"
      :state="validationState"
      value-field="id"
      text-field="name"
      stacked
    />
    <BFormInvalidFeedback :state="validationState">
      Please select at least one user
    </BFormInvalidFeedback>
  </BFormGroup>
  <!-- #endregion template -->
</template>

<script setup lang="ts">
import {computed, ref} from 'vue'

interface User {
  id: number
  name: string
}

const users: User[] = [
  {id: 1, name: 'Alice'},
  {id: 2, name: 'Bob'},
  {id: 3, name: 'Charlie'},
]

const selectedIds = ref<readonly number[]>([])

const validationState = computed(() => selectedIds.value.length > 0)
</script>

Type-Safe API Responses

Type safety is especially valuable when working with API data that uses different naming conventions:

Selected user IDs: [ "usr_001" ]
HTML
vue
<template>
  <!-- #region template -->
  <div>
    <BFormCheckboxGroup
      id="checkbox-type-safe-api"
      v-model="selectedUsers"
      :options="apiUsers"
      value-field="userId"
      text-field="username"
      disabled-field="disabled"
    />
    <div class="mt-3">
      Selected user IDs: <strong>{{ selectedUsers }}</strong>
    </div>
  </div>
  <!-- #endregion template -->
</template>

<script setup lang="ts">
import {ref} from 'vue'

interface ApiUser {
  userId: string
  username: string
  email: string
  disabled?: boolean
}

// Simulated API response
const apiUsers: ApiUser[] = [
  {userId: 'usr_001', username: 'alice@example.com', email: 'alice@example.com'},
  {userId: 'usr_002', username: 'bob@example.com', email: 'bob@example.com'},
  {
    userId: 'usr_003',
    username: 'charlie@example.com',
    email: 'charlie@example.com',
    disabled: true,
  },
]

// TypeScript knows selectedUsers is readonly string[]
const selectedUsers = ref<readonly string[]>(['usr_001'])
</script>

Type-Safe Enums

Type safety works with TypeScript enums for strongly-typed value constraints:

Selected roles: [ "editor", "viewer" ]
HTML
vue
<template>
  <!-- #region template -->
  <div>
    <BFormCheckboxGroup
      id="checkbox-type-safe-enum"
      v-model="selectedRoles"
      :options="roleOptions"
      value-field="value"
      text-field="label"
      disabled-field="disabled"
    />
    <div class="mt-3">
      Selected roles: <strong>{{ selectedRoles }}</strong>
    </div>
  </div>
  <!-- #endregion template -->
</template>

<script setup lang="ts">
import {ref} from 'vue'
import {UserRole} from './CheckboxTypeSafeEnumTypes'

interface RoleOption {
  value: UserRole
  label: string
  disabled?: boolean
}

const roleOptions: RoleOption[] = [
  {value: UserRole.Admin, label: 'Administrator'},
  {value: UserRole.Editor, label: 'Editor'},
  {value: UserRole.Viewer, label: 'Viewer'},
  {value: UserRole.Guest, label: 'Guest', disabled: true},
]

// TypeScript knows selectedRoles is UserRole[]
const selectedRoles = ref<UserRole[]>([UserRole.Editor, UserRole.Viewer])
</script>

Benefits

  • IDE autocomplete - Your editor suggests valid field names as you type
  • Compile-time validation - Typos and invalid field names are caught before runtime
  • Type inference - The v-model type is automatically inferred from your value field
  • Refactoring safety - Renaming fields in your interface updates all usages

Backward Compatibility

Type safety is completely opt-in and maintains 100% backward compatibility. Existing code without explicit types continues to work exactly as before:

vue
<!-- Works without type annotations -->
<ComponentName v-model="selected" :options="items" />

To enable type safety, simply provide explicit types for your data:

typescript
interface MyItem {
  id: number
  name: string
}

const items: MyItem[] = [...]

Global Defaults Limitation

Due to technical limitations with TypeScript generic components, this component cannot fully participate in the global defaults system provided by createBootstrap({ components: {...} }) or BApp. However:

  • Commonly-customized props like buttonVariant, size, and state DO support global defaults
  • ⚠️ Other props will use their hardcoded default values only
  • ✅ You can still override any prop on individual component instances

This trade-off enables full type safety with IDE autocomplete and compile-time validation.

Props That Support Global Defaults

The following props support both component-specific defaults and global defaults:

  • button-variant - Button variant for button-style checkboxes/radios (default: 'secondary')
  • size - Size of the checkbox/radio (default: 'md')
  • state - Validation state (default: null)

Default Value Precedence

When using these components, default values are resolved in this order (highest priority first):

  1. Explicit prop on component instance - Value you provide directly
  2. Component-specific defaults - Set via <BApp :defaults="{ BFormCheckboxGroup: {...} }"> or createBootstrap({ components: { BFormCheckboxGroup: {...} } })
  3. Global defaults - Set via <BApp :defaults="{ global: {...} }"> or createBootstrap({ components: { global: {...} } })
  4. Hardcoded default - Component's built-in fallback value

Example:

BApp Pattern:

template
<template>
  <BApp
    :defaults="{
      global: {
        buttonVariant: 'primary', // Applied to all components
        size: 'lg',
      },
      BFormCheckboxGroup: {
        buttonVariant: 'danger', // Specific to checkbox groups
        size: 'sm',
      },
    }"
  >
    <!-- Uses component defaults: danger variant, sm size -->
    <BFormCheckboxGroup
      :options="options"
      buttons
    />

    <!-- Explicit prop overrides everything: success variant -->
    <BFormCheckboxGroup
      :options="options"
      buttons
      button-variant="success"
    />

    <!-- Individual checkboxes outside a group use global defaults: primary variant -->
    <BFormCheckbox
      button
      value="a"
      >Option A</BFormCheckbox
    >
  </BApp>
</template>

<script setup lang="ts">
const options = [
  {text: 'Option 1', value: 1},
  {text: 'Option 2', value: 2},
]
</script>

Plugin Pattern:

template
// In main.ts or app setup:
import {createBootstrap} from 'bootstrap-vue-next'

app.use(
  createBootstrap({
    components: {
      global: {
        buttonVariant: 'primary', // Applied to all components
        size: 'lg',
      },
      BFormCheckboxGroup: {
        buttonVariant: 'danger', // Specific to checkbox groups
        size: 'sm',
      },
    },
  })
)

TIP

When checkboxes or radios are used within their group component (BFormCheckboxGroup or BFormRadioGroup), the group's defaults automatically cascade to all child checkboxes/radios. You don't need to set defaults on individual BFormCheckbox or BFormRadio components.

ts
// This WILL work for buttonVariant, size, and state:
createBootstrap({
  components: {
    BFormCheckboxGroup: {
      buttonVariant: 'primary', // ✅ Will be applied
      size: 'lg', // ✅ Will be applied
      state: false, // ✅ Will be applied
      stacked: true, // ⚠️ Will NOT be applied (use prop override)
    },
    global: {
      size: 'sm', // ✅ Will be applied as fallback if BFormCheckboxGroup.size not set
    },
  },
})

Component Reference

<BFormCheckbox>

PropTypeDefaultDescription
aria-labelstringundefined Sets the value of `aria-label` attribute on the rendered element
aria-labelledbystringundefined The ID of the element that provides a label for this component. Used as the value for the `aria-labelledby` attribute
autofocusbooleanfalse When set to `true`, attempts to auto-focus the control when it is mounted, or re-activated when in a keep-alive. Does not set the `autofocus` attribute on the control
buttonbooleanfalse When set, renders the checkbox with the appearance of a button
button-groupbooleanfalse When set, renders the checkbox as part of a button group (it doesn't enclose the checkbox and label with a div). It is not necessary to set this to true if this is part of a CheckboxGroup as it is handled internally
button-variantButtonVariant | null'secondary' Applies one of Bootstrap's theme colors when in `button` mode
disabledbooleanfalse When set to `true`, disables the component's functionality and places it in a disabled state
formstringundefined ID of the form that the form control belongs to. Sets the `form` attribute on the control
idstringundefined Used to set the `id` attribute on the rendered content, and used as the base to generate any additional element IDs as needed
indeterminatebooleanfalse Set to true to show the checkbox as indeterminate, false to show its normal checked/unchecked.
inlinebooleanfalse When set, renders the checkbox as an inline element rather than as a 100% width block
input-classClassValueundefined Class to be applied to the body of the checkbox item
model-valueCheckboxValue | readonly CheckboxValue[]undefined The current value of the checkbox(es). Must be an array when there are multiple checkboxes bound to the same v-model. Looking for `value` - use `modelValue` instead.
namestringundefined Sets the value of the `name` attribute on the form control
plainbooleanfalse Render the form control in plain mode, rather than custom styled mode
requiredbooleanundefined Adds the `required` attribute to the form control
reversebooleanfalse When set, renders the checkbox or switch on the opposite side
sizeSize'md' Set the size of the component's appearance. 'sm', 'md' (default), or 'lg'
stateValidationStateundefined Controls the validation state appearance of the component. `true` for valid, `false` for invalid, or `null` for no validation state
switchbooleanfalse When set, renders the checkbox with the appearance of a switch
unchecked-valueCheckboxValuefalse Value returned when this checkbox is unchecked. Note not applicable when multiple checkboxes bound to the same v-model array
valueCheckboxValuetrue Value returned when this checkbox is checked
wrapper-attrsReadonly<AttrsValue>undefined Attributes to be applied to the wrapper element
EventArgsDescription
update:indeterminate
value: boolean - Value of the indeterminate state - true for indeterminate, false for deterministic state.
Emitted when the indeterminate state of the checkbox is changed
update:model-value
value: CheckboxValue | readonly CheckboxValue[] - Value of the checkbox. Value will be an array for grouped checkboxes or a single value for standalone checkboxes. Looking for the `input` or `change` event - use `update:model-value` instead.
Emitted when the checked value is changed
NameScopeDescription
defaultContent to place in the label of the form checkbox

<BFormCheckboxGroup>

PropTypeDefaultDescription
aria-invalidAriaInvalidundefined Sets the `aria-invalid` attribute value on the wrapper element. When not provided, the `state` prop will control the attribute
autofocusbooleanfalse When set to `true`, attempts to auto-focus the control when it is mounted, or re-activated when in a keep-alive. Does not set the `autofocus` attribute on the control
button-variantButtonVariant | null'secondary' Specifies the Bootstrap contextual color theme variant to apply to the button style checkboxes
buttonsbooleanfalse When set, renders the checkboxes in this group with button styling
disabledbooleanfalse When set to `true`, disables the component's functionality and places it in a disabled state
disabled-fieldstring'disabled' Field name in the `options` array that should be used for the disabled state
formstringundefined ID of the form that the form control belongs to. Sets the `form` attribute on the control
idstringundefined Used to set the `id` attribute on the rendered content, and used as the base to generate any additional element IDs as needed
model-valuereadonly CheckboxValue[]'() => []' The current value of the checked checkboxes in the group. Must be an array when there are multiple checkboxes. Looking for `value` - use `modelValue` instead.
namestringundefined Sets the value of the `name` attribute on the form control
optionsreadonly CheckboxOptionRaw[]'() => []'
plainbooleanfalse Render the form control in plain mode, rather than custom styled mode
requiredbooleanundefined Adds the `required` attribute to the form control
reverseboolean'false' When set, renders the checkboxes and switches on the opposite side
sizeSize'md' Set the size of the component's appearance. 'sm', 'md' (default), or 'lg'
stackedbooleanfalse When set, renders the checkbox group in stacked mode
stateValidationStateundefined Controls the validation state appearance of the component. `true` for valid, `false` for invalid, or `null` for no validation state
switchesbooleanfalse When set, renders the checkboxes in the group with switch styling
text-fieldstring'text' Field name in the `options` array that should be used for the text label
validatedbooleanfalse When set, adds the Bootstrap class `was-validated` to the group wrapper
value-fieldstring'value' Field name in the `options` array that should be used for the value
EventArgsDescription
update:model-value
value: CheckboxValue[] - Value of the checkboxes. Value will be an array.
Emitted when the selected value(s) are changed. Looking for the `input` or `change` event - use `update:model-value` instead.
NameScopeDescription
defaultContent (form checkboxes) to place in the form checkbox group
firstSlot to place for checkboxes so that they appear before checks generated from options prop
option
value: string | number | undefined - The value of the checkbox button
disabled: boolean | undefined - Whether the checkbox button is disabled
text: string | undefined - The text to display for the checkbox button
Use this slot to have finer control over the content rendered inside each checkbox button.