Skip to content

GhostCheckbox ​

GhostCheckbox is an unstyled native checkbox with a boolean v-model and a consumer-owned mixed state. Import it from @ghostvue/vue for headless use, or from @ghostvue/themes for the default visual treatment.

Notification preferences

Email preferences panel with described options, a mixed select-all, and a locked required alert.

Email notifications

Choose what reaches ada@analytical-engines.example.

Project activity

Updates from projects you follow.

Account

Security and billing for you.

The preferences panel composes themed GhostCheckbox with GhostField: each option's label points at its checkbox with for, and its description is linked through aria-describedby, so screen readers announce "Weekly digest, checkbox, not checked" followed by the hint. The checkbox keeps its full hit target in the first column, and the label's first line is centered on the painted box, so long labels and descriptions wrap under the text instead of under the control.

All project activity is a select-all. It is checked when every child is on, indeterminate when only some are, and toggling it sets every child; the v-model stays boolean. Security alerts sits in a disabled field, which disables the checkbox and mutes its label: it stays visible so members know the alert exists, but they cannot turn it off. Disabled checkboxes are left out of form submission, so the seeded form posts mentions and assignments but not security. On narrow previews the actions stack at full width.

Basic use ​

Wrap the control in a <label> or associate the label with for and id. Use GhostField when the same checkbox needs a description or error. A named checkbox sends its value when checked and enabled.

Themed use ​

Themed

Size and tone on the @ghostvue/themes wrapper, with checked, mixed, and disabled states.

States

Tone and size

The themed sample shows every state side by side, then each tone and size. Mixed clears on the first click, the way a resolved select-all would.

Importing the themed component loads the default stylesheet. Visual props exist only on this wrapper:

@ghostvue/themes adds these to the headless GhostCheckbox API, which it forwards:

PropTypeDefaultDescription
size'sm' | 'md' | 'lg'"md"Control size. The default omits data-size so CSS can treat a missing hook as md.
tone'accent' | 'neutral' | 'danger'"accent"Semantic color intent. The default omits data-tone.

The hit target uses --ghost-control-size-*-min. The painted box uses --ghost-action-icon-size. Corners use --ghost-radius-sm. Color comes from --ghost-action-*-* by tone. You can also import the stylesheet and wrap unstyled checkboxes in .ghost-theme when you want a region of headless components to pick up the defaults. See the default theme guide.

Mixed (select-all) ​

In the notification preferences, focus All project activity. It starts mixed because two of its three child options are on. Press Space to turn all three on, then clear any child to return the parent to mixed. Restore defaults restores the original two selections.

Keep v-model boolean. Derive indeterminate from the child states and apply the parent toggle to each child. Give the children a shared form name and individual value attributes.

For a list bound to a single string[] model with shared form reset and focus restoration, use GhostCheckboxGroup.

Field composition ​

Spread GhostFieldControl slot props onto the checkbox to receive the field's generated id, aria-describedby, aria-invalid, disabled, and required. The slot's raw invalid flag is not an HTML attribute, so the checkbox drops it; aria-invalid carries that state. Every other attribute still falls through.

Unlabeled and form use ​

Row-selection checkboxes often have no visible text. Name them with aria-label or aria-labelledby. Give form checkboxes a name so they participate in native submission. The browser uses checked to decide whether to include the value.

Customize with headless checkboxes ​

Import from @ghostvue/vue to supply your own styling, or bind the composable to a native checkbox.

Basic Headless

Labeled native checkbox with a boolean v-model.

Composable Headless

Same contract as GhostCheckbox, applied to a native host.

Headless select-all ​

Indeterminate Headless

Select-all mixed state computed from child checkboxes.

Component refs ​

Component ref Headless

Template refs expose element, focus, and blur.

The ref exposes element, focus(options?), and blur(). Before mount and after unmount, element is null and the methods are safe no-ops.

Styling ​

The unstyled component renders one native <input type="checkbox"> with class ghost-checkbox, data-part="root", data-state="checked" while checked and not mixed, and data-state="indeterminate" while mixed. Unchecked omits data-state. Native disabled is the unavailable hook.

css
.ghost-checkbox[data-state='indeterminate'] {
  /* Applies only while mixed. */
}

API ​

PropTypeDefaultDescription
defaultValuebooleanfalseInitial checked state when modelValue is omitted. Later changes are ignored.
disabledbooleanfalseNative disabled semantics: no activation, no sequential focus, and excluded from form submission.
indeterminatebooleanfalseMixed state for select-all and similar. Applied through the DOM indeterminate property. Consumer-owned; not part of the v-model.
modelValueboolean—Controlled checked state. Omit it for uncontrolled use. undefined is uncontrolled; false is unchecked. Mixed is the indeterminate prop, not a third model value.

v-model emits update:modelValue with a boolean after native activation. type is always "checkbox". checked is not a public prop; the model owns that state.

All other native input attributes and event listeners fall through to the root <input>. The component does not generate an id; pass one as a native attribute when a for association needs it.

Accessibility and environment behavior ​

Enabled checkboxes retain native Space toggle, pointer, touch, and focus behavior. Enter does not toggle; in a form it submits. Disabled checkboxes use native disabled semantics. The component never sets role or aria-checked: native checked and indeterminate already expose those states, and aria-checked on a native checkbox is ignored.

SSR markup is deterministic from props for checked and disabled. Mixed cannot be an HTML attribute; SSR still sets data-state="indeterminate", and the DOM property is written after mount.

See the GhostCheckbox specification for the complete behavior and compatibility contract.