Checkbox

Styled checkbox with label, error states, and indeterminate support.

uiforminteractive

Installation

Copy the component file into your project's src/lib/components/ directory.

templates/Checkbox.svelte

Usage

<script>
  import Checkbox from '$lib/components/Checkbox.svelte';

  let accepted = $state(false);
  let notifications = $state(true);
  let newsletter = $state(false);
  let indeterminateState = $state(true);
</script>

<!-- Basic checkbox -->
<Checkbox
  bind:checked={accepted}
  label="I accept the terms and conditions"
/>

<!-- Checkbox with helper text -->
<Checkbox
  bind:checked={notifications}
  label="Enable notifications"
  helperText="Receive email updates about your account"
/>

<!-- Required checkbox with error -->
<Checkbox
  bind:checked={accepted}
  label="Accept terms"
  required
  error={!accepted ? 'You must accept the terms to continue' : ''}
/>

<!-- Disabled checkbox -->
<Checkbox
  checked={true}
  label="This option is always enabled"
  disabled
/>

<!-- Checkbox without label (icon only) -->
<Checkbox
  bind:checked={newsletter}
/>

<!-- Indeterminate checkbox (useful for "select all" functionality) -->
<Checkbox
  bind:checked={notifications}
  indeterminate={indeterminateState}
  label="Select all notifications"
/>

Props

PropTypeDefaultDescription
checkedbooleanfalseWhether the checkbox is checked (bindable)
labelstring''Label text displayed next to the checkbox
disabledbooleanfalseWhether the checkbox is disabled
requiredbooleanfalseWhether the checkbox is required (adds asterisk to label)
errorstring''Error message to display below checkbox
helperTextstring''Helper text displayed below checkbox when no error
idstring''Checkbox id attribute (auto-generated if not provided)
namestring''Checkbox name attribute for form submission
valuestring''Checkbox value attribute (useful in checkbox groups)
indeterminatebooleanfalseWhether the checkbox is in an indeterminate state (partially checked)
classstring''Additional CSS classes for the checkbox wrapper

Files