Skip to main content

Starwind UI v3.7 is here with stable Vue and Svelte, the new Chart component, and full RTL support. Read the release notes

Installation

Usage

---
import { Checkbox } from "@/components/starwind/checkbox";
---
<Checkbox id="demo-checkbox" label="Checkbox" />

Variants

Sizes

Disabled

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Checkbox

Inherits span attributes. Omits `defaultChecked`, `id`, and `onChange`.

Contains the following additional props:

Prop Type Default Toggle details
defaultChecked boolean —
Description
Sets the initial checked state when the choice is uncontrolled.
Classification
Primitive override
Primitive prop
checkbox.Root.defaultChecked
label string —
Description
Provides accessible text for the component.
Classification
Wrapper prop
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Styled variant
variant "default" | "primary" | "secondary" | "info" | "success" | "warning" | "error" "default"
Description
Selects the component's visual variant.
Classification
Styled variant

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Checkbox.

Primitive API

Runtime API

Checkbox primitive
createCheckbox from @starwind-ui/runtime/checkbox

Changelog

View version history v2.1.1 12 releases

v2.1.1

  • Checkbox now limits its transition to visual colors and opacity, so layout changes do not animate the control.
  • In Vue, this component now needs Vue 3.5.21 or newer.
  • Internal code cleanup, such as unused code and import order. This cleanup does not change behavior.

v2.1.0

  • In Svelte, a defined checked that you pass when Checkbox mounts now stays under your control, as in React and Vue. To change it, use bind: or update your state in the change callback. A form reset keeps it. If you pass undefined at mount, Checkbox keeps its own state.
  • In Vue, a Boolean prop that you leave out, such as defaultChecked, no longer becomes false. The default of the underlying component applies.
  • Inside a Field in Astro, Checkbox now clears when the form resets. Before, it stayed checked.

v2.0.3

  • When you set indeterminate, the box now fills with the variant color and shows a minus icon in every variant. The error border still shows when the field is invalid. Before, the default variant looked unchecked in light mode, and the other variants showed only a faint check.
  • Checkbox now gets its name from a <label for> that points at its id. Before, screen readers read it with no name.
  • In Astro, a required Checkbox in a plain HTML form now shows the browser message and gets focus. Before, the form did not submit, and no message showed.
  • When the browser flags a required Checkbox as invalid, focus now goes to the checkbox that the user sees.

v2.0.2

  • In React, the initial native checkbox value now matches the checked value supplied by your app.
  • Vue Checkbox keeps its previous checked value when a change is canceled.
  • Fixed React and Vue form resets restoring the wrong value after a control is recreated. Resets now use its original default.
  • Reduced the JavaScript loaded by Checkbox when it is used without Field.

v2.0.1

  • In React, you can cancel a change before it applies. The component then keeps its previous state, and it shows only the changes that apply.

v2.0.0

  • Checkbox now gets its behavior from Starwind Runtime. Runtime handles the checked state, the native form value, and the checked-change events.
  • See the Checkbox Primitive for the unstyled parts and the behavior API.

v1.4.3

  • The Tailwind variants now live in their own variants.ts file in the component folder.

v1.4.1

  • add aria-invalid styling

v1.4.0

  • style and focus state updates

v1.3.0

  • Add a data-slot attribute to all components to enable global styling updates

v1.2.0

  • No longer require an “id” prop
  • Adjust component to use type VariantProps from tailwind-variants. This provides greater type safety and cleans up component frontmatter.

v1.1.0

  • tailwind-variants now implemented. This uses tailwind-merge under the hood to merge Tailwind classes without style conflicts, allowing you to override any existing classes using the “class” prop.