Skip to content

Checkbox ​

A checkbox is a single yes or no. CheckboxControl is the box, CheckboxIndicator is the mark inside it, and CheckboxContent wraps the box together with its label so the whole row is the hit area.

ts
import { Checkbox, CheckboxContent, CheckboxControl, CheckboxIndicator } from "ropav";
variant
template
<Checkbox>
  <CheckboxContent>
    <CheckboxControl>
      <CheckboxIndicator />
    </CheckboxControl>
    Accept the terms
  </CheckboxContent>
</Checkbox>

Indeterminate ​

is-indeterminate is the third state, for a checkbox that summarises others: some of the boxes below it are ticked and some are not. It is a display state, not a value — the checkbox is still either selected or not underneath, and clicking it resolves the mixed state one way.

checkbox-indeterminate.vue
vue
<script setup lang="ts">
import { Checkbox, CheckboxContent, CheckboxControl, CheckboxIndicator } from "ropav";
</script>

<template>
  <div class="stack">
    <Checkbox
      v-for="state in ['unchecked', 'checked', 'mixed'] as const"
      :key="state"
      :is-indeterminate="state === 'mixed'"
      :is-selected="state === 'checked'"
    >
      <CheckboxContent>
        <CheckboxControl>
          <CheckboxIndicator />
        </CheckboxControl>
        {{ state }}
      </CheckboxContent>
    </Checkbox>
  </div>
</template>

<style scoped>
.stack {
  display: flex;
  flex-direction: column;
  gap: calc(var(--rp-spacing) * 3);
}
</style>

Groups ​

For several checkboxes that share a name, a validation state and one error message, use a CheckboxGroup.

Accessibility ​

  • The real control is a native <input type="checkbox">, kept in the accessibility tree and out of sight. The box you see is drawn beside it, so the state a screen reader announces is the browser's own.
  • CheckboxContent makes the label part of the control, which is what gives the row its hit area — a target far larger than the box, and the reason the label does not need its own handler.

API ​

Checkbox

PropTypeDefaultDescription
ariaDescribedbystring—Ids of the elements that describe the checkbox, on top of any nested help text.
ariaLabelstring—Accessible name, for a checkbox with no visible label.
ariaLabelledbystring—Ids of the elements that name the checkbox.
defaultSelectedboolean—Whether it starts ticked, when uncontrolled.
formstring—id of the form to submit with, for a checkbox rendered outside it.
idstring—Lands on the hidden input rather than on the wrapper, because the input is the checkbox as far as assistive technology is concerned.
isDisabledboolean—Whether the checkbox is disabled — no interaction, no submission.
isIndeterminateboolean—Shows the mixed state, for a checkbox standing in for a partly selected set.
isInvalidboolean—Whether the value fails validation. Setting it either way takes the field over: false claims the checkbox is valid and shadows validate, the browser and the server alike. Ignored inside a group, which validates on the group's behalf.
isReadOnlyboolean—Whether the value can be read but not changed.
isRequiredboolean—Whether it has to be ticked for the form to submit.
isSelectedboolean—Whether the checkbox is ticked. Makes it controlled, and is ignored inside a group.
namestring—Name submitted with the form. Taken from the surrounding group when unset.
validateValidationFunction<boolean>—Checks the value and returns a message when it is not acceptable.
validationBehavior"aria" | "native""native"How the checkbox reports validation. Inherited from the surrounding form when unset.
valuestring"on"Value submitted with the form while the checkbox is ticked, and the value it contributes to a surrounding group's selection.
variant"primary" | "secondary""primary"Visual variant. Taken from the surrounding group when unset.

The default slot receives:

Slot propType
isDisabledboolean
isIndeterminateboolean
isInvalidboolean
isReadOnlyboolean
isRequiredboolean
isSelectedboolean
EventPayload
changeboolean
update:isSelectedboolean

CheckboxContent

The default slot receives:

Slot propType
isDisabledboolean
isFocusedboolean
isFocusVisibleboolean
isHoveredboolean
isIndeterminateboolean
isInvalidboolean
isPressedboolean
isReadOnlyboolean
isRequiredboolean
isSelectedboolean

CheckboxControl

Slots: default.

CheckboxIndicator

The default slot receives:

Slot propType
isDisabledboolean
isIndeterminateboolean
isInvalidboolean
isReadOnlyboolean
isRequiredboolean
isSelectedboolean