Skip to content

Checkbox

The Checkbox component provides an interactive multi-select list. It supports keyboard navigation, custom styling, and responsive layouts.

Basic Usage

Checkbox supports both vertical and horizontal layouts:

vue
<template>
  <Col :gap="2">
    <!-- Vertical layout (default) -->
    <Checkbox
      v-model="selectedFruits"
      label="Select your favorite fruits:"
      :options="fruitOptions"
      :height="5"
    />

    <!-- Show selected -->
    <Box :padding="1">
      <TextBox>Selected: {{ selectedFruits.join(', ') }}</TextBox>
    </Box>

    <!-- Horizontal layout -->
    <Checkbox
      v-model="notifications"
      label="Notification preferences:"
      :options="notificationOptions"
      direction="horizontal"
    />

    <!-- With disabled options -->
    <Checkbox
      v-model="selectedRoles"
      label="Assign user roles:"
      :options="roleOptions"
      :height="6"
    />
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Checkbox, Box, TextBox, Col } from 'vuetty';

const selectedFruits = ref(['apple']);
const fruitOptions = [
  { label: 'Apple', value: 'apple' },
  { label: 'Banana', value: 'banana' },
  { label: 'Orange', value: 'orange' },
  { label: 'Grape', value: 'grape' },
  { label: 'Mango', value: 'mango' }
];

const notifications = ref(['email']);
const notificationOptions = [
  { label: 'Email', value: 'email' },
  { label: 'SMS', value: 'sms' },
  { label: 'Push', value: 'push' }
];

const selectedRoles = ref(['user']);
const roleOptions = [
  { label: 'Administrator', value: 'admin', disabled: true },
  { label: 'Moderator', value: 'moderator' },
  { label: 'User', value: 'user' },
  { label: 'Guest', value: 'guest' }
];
</script>

Props

Model

PropTypeDefaultDescription
modelValueArray[]Array of selected values (v-model)

Options

PropTypeDefaultDescription
optionsArray[]Array of option objects. Each option must have label and value properties. Can also include disabled: true to disable individual options.

Option Object Structure:

javascript
{
  label: 'Display Label',    // Text shown to user
  value: 'option-value',     // Value used in modelValue
  disabled: false            // Optional: mark as non-selectable
}

Display

PropTypeDefaultDescription
labelString''Label displayed above the checkbox list
directionString'vertical'Layout direction: 'vertical' or 'horizontal'
heightNumber | StringnullNumber of visible items (vertical mode only)
widthNumber | StringnullComponent width in characters (null = auto)
itemSpacingNumber2Spacing between items in characters
hintString | Boolean'default'Hint text shown when focused. Use 'default' for standard hints, false to disable, or pass custom text

State

PropTypeDefaultDescription
disabledBooleanfalseDisable the entire checkbox component

Styling

PropTypeDefaultDescription
colorStringundefinedText color (supports named colors and hex codes)
bgStringundefinedBackground color
focusColorString'cyan'Color for focused item highlight
selectedColorString'green'Color for selected checkbox indicators
highlightColorString'yellow'Color for highlighted item cursor
boldBooleanfalseBold text
dimBooleanfalseDimmed text

Layout Props (Box Props)

PropTypeDefaultDescription
flexNumber | StringnullFlex shorthand when inside a flex container
flexGrowNumbernullFlex grow factor
flexShrinkNumbernullFlex shrink factor
flexBasisNumber | StringnullFlex basis
alignSelfStringnullSelf alignment: 'auto', 'flex-start', 'flex-end', 'center', 'stretch', 'baseline'
widthNumber | StringnullWidth (chars or %)
heightNumber | StringnullHeight (rows)
minWidthNumbernullMinimum width
maxWidthNumbernullMaximum width
minHeightNumbernullMinimum height
maxHeightNumbernullMaximum height
paddingNumbernullPadding
paddingLeftNumbernullLeft padding
paddingRightNumbernullRight padding
paddingTopNumbernullTop padding
paddingBottomNumbernullBottom padding
marginNumbernullMargin
marginLeftNumbernullLeft margin
marginRightNumbernullRight margin
marginTopNumbernullTop margin
marginBottomNumbernullBottom margin

Events

EventPayloadDescription
update:modelValueArrayEmitted when selection changes. The new array of selected values.
changeArrayEmitted when selection changes (same as update:modelValue)
focus-Emitted when component receives keyboard focus
blur-Emitted when component loses keyboard focus

Hints

Checkbox displays helpful keyboard hints when focused. You can customize or disable these hints.

Controlling Hints

By default, Checkbox shows direction-aware navigation hints:

vue
<template>
  <!-- Default hint - automatically adjusts for direction -->
  <Checkbox
    v-model="selected"
    :options="options"
    direction="vertical"
  />
  <!-- Shows: "↑↓ Navigate • Space/Enter to toggle • Tab to next field" -->

  <!-- Custom hint text -->
  <Checkbox
    v-model="selected"
    :options="options"
    hint="Press Space to toggle selected items"
  />

  <!-- Disable hints -->
  <Checkbox
    v-model="selected"
    :options="options"
    :hint="false"
  />
</template>

<script setup>
import { ref } from 'vue';
import { Checkbox } from 'vuetty';

const selected = ref([]);
const options = [
  { label: 'Option 1', value: 'opt1' },
  { label: 'Option 2', value: 'opt2' },
  { label: 'Option 3', value: 'opt3' }
];
</script>

TIP

Default hints automatically adjust based on the direction prop:

  • Vertical: Shows ↑↓ arrow indicators
  • Horizontal: Shows ←→ arrow indicators

Keyboard Navigation

KeyAction
/ Move to previous option
/ Move to next option
HomeJump to first option
EndJump to last option
Page UpMove up one page (height)
Page DownMove down one page (height)
Space / EnterToggle current option selection
TabNavigate to next focusable component

Advanced Examples

Custom Styling

vue
<template>
  <Checkbox
    v-model="features"
    label="Select features to enable:"
    :options="featureOptions"
    :height="5"
    focus-color="magenta"
    selected-color="yellow"
    highlight-color="blue"
    color="white"
    bold
  />
</template>

<script setup>
import { ref } from 'vue';
import { Checkbox } from 'vuetty';

const features = ref(['caching']);
const featureOptions = [
  { label: 'Caching', value: 'caching' },
  { label: 'Compression', value: 'compression' },
  { label: 'Encryption', value: 'encryption' },
  { label: 'Logging', value: 'logging' }
];
</script>

Form Integration

vue
<template>
  <Col>
    <Box :padding="2" color="cyan">
      <TextBox bold>User Preferences</TextBox>
    </Box>

    <Checkbox
      v-model="form.preferences"
      label="Notification channels:"
      :options="notificationOptions"
      :height="4"
      @change="onChange"
    />

    <Box :padding="1">
      <TextBox dim>Use arrow keys to navigate, Space to select</TextBox>
    </Box>
  </Col>
</template>

<script setup>
import { reactive } from 'vue';
import { Checkbox, Box, TextBox, Col } from 'vuetty';

const form = reactive({
  preferences: ['email']
});

const notificationOptions = [
  { label: 'Email Notifications', value: 'email' },
  { label: 'SMS Alerts', value: 'sms' },
  { label: 'Push Notifications', value: 'push' },
  { label: 'Weekly Digest', value: 'digest' }
];

const onChange = (newSelection) => {
  console.log('Preferences updated:', newSelection);
};
</script>

Responsive Layout

vue
<template>
  <Row>
    <Col :flex="1">
      <Checkbox
        v-model="selected"
        :options="options"
        label="Options:"
        :height="8"
        :width="30"
      />
    </Col>
    <Col :flex="2">
      <Box :padding="1">
        <TextBox>Details panel</TextBox>
      </Box>
    </Col>
  </Row>
</template>

<script setup>
import { ref } from 'vue';
import { Checkbox, Box, TextBox, Row, Col } from 'vuetty';

const selected = ref([]);
const options = [
  { label: 'Option 1', value: 'opt1' },
  { label: 'Option 2', value: 'opt2' },
  { label: 'Option 3', value: 'opt3' }
];
</script>

Released under the MIT License.