Skip to content

GhostCheckboxGroup ​

GhostCheckboxGroup manages a visible set of GhostCheckbox controls with a single string[] v-model, native form submission, native form reset, and focus restoration when a focused option disappears. Import it from @ghostvue/themes for the default fieldset spacing and legend typography, or see Advanced: headless composition for unstyled @ghostvue/vue usage.

Notification preferences

Themed notification preferences with array v-model, mixed select-all, locked choice, and FormData.getAll readout.

Email notifications

Choose what reaches ada@analytical-engines.example.

Project activity

Updates from projects you follow.

Account

Security and billing for you.

Model
["mentions","assignments","security"]
FormData
Submit to inspect getAll("notifications")

The preferences panel binds one string[] model per group (project and account) while keeping a shared name="notifications" so form submission yields FormData.getAll('notifications') in DOM order. All project activity omits value, so it stays a standalone boolean checkbox with consumer-derived indeterminate state. Security alerts is locked (disabled), so it displays as checked in the model without being submitted.

Basic use ​

Basic

Themed checkbox group with a legend and three visible options.

Release updates

Selected: email

Any GhostCheckbox inside GhostCheckboxGroup with a string value attribute joins the group automatically. A GhostCheckbox without value stays standalone.

Choice cards ​

Room extras

Booking extras as GhostCheckboxCard choices, each its own tab stop, with the array model.

Extras

Extras: breakfast

GhostCheckboxCard is a card-shaped member of GhostCheckboxGroup. Its root is a native <label> around a group-member GhostCheckbox, so a click anywhere on the card toggles it, with no script. The group keeps its array model, form submission, reset, and development warnings, because the input inside the card is an ordinary member. Cards and plain GhostCheckbox members can share one group, and each enabled card is its own tab stop.

The default slot is the option's name and the description slot is its detail. The card root carries data-state="checked" while checked and data-disabled when the card or the group is disabled. indeterminate is not supported on a card: a mixed "select all" stays a plain GhostCheckbox. GhostCheckboxCard must sit inside GhostCheckboxGroup; a single "I agree" checkbox is a plain GhostCheckbox in a label.

class, style, and data-visual-state stay on the card root. Every other attribute and listener goes to the inner checkbox, with the same name and form rules as any member. Card content must be phrasing content with no links or buttons, because the card is a <label>. The card's accessible name is its default slot text, and the description slot is its accessible description. A consumer aria-labelledby replaces the generated name; a consumer aria-describedby is added after the description.

Forms and native reset ​

Form reset

Native form submission and reset restoring the default selection.

Export columns

Model: ["id","total"]

Place GhostCheckboxGroup inside its <form>. defaultValue sets the uncontrolled seed and the native form-reset baseline (shallow-copied once at setup). When the ancestor form resets, the group restores that baseline (or [] when controlled without defaultValue) unless reset was preventDefault()ed.

An external form attribute on the group root or on a member checkbox is consumed, omitted from the DOM, and warns in development (GHOST015) so submission and reset never target different forms.

Error state ​

Error state

Group-level invalid state and error text linked via aria-describedby.

API token scopes

Select at least one permission for this token.

Choose at least one token scope before generating a key.

Set invalid on GhostCheckboxGroup (or spread GhostFieldControl slot props onto the root) to expose aria-invalid="true" and data-state="invalid" on the group root and link error copy with aria-describedby. Member checkboxes do not receive aria-invalid from the group unless you pass it to an individual option.

Array model and ordering ​

The group keeps stable consumer order in modelValue:

  • Checking a value appends it ([...current, value]).
  • Unchecking a value removes every occurrence (current.filter((x) => x !== value)).
  • Existing entries keep their position and any consumer-supplied duplicates.
  • Consumer arrays are never mutated (Object.freeze([...]) arrays are supported); every emit produces a new array.
  • FormData.getAll(name) always follows mounted, enabled DOM order from the underlying native checkboxes.
Before (modelValue)ActionEmitted update:modelValueFormData.getAll(name)
['mentions']Check digest['mentions', 'digest']['mentions', 'digest']
['mentions', 'digest']Uncheck mentions['digest']['digest']
['digest']Check mentions (before digest in DOM)['digest', 'mentions']['mentions', 'digest']
['mentions', 'legacy-sms']Mount without legacy-sms optionnone['mentions']
['mentions', 'digest']Unmount or reorder digestnoneReflects DOM order
['mentions']Controlled parent ignores digest click['mentions', 'digest']['mentions']

Unknown, removed, and locked options ​

  • Unknown and unmounted values stay in modelValue. Filtering, hiding, or lazy-loading options never erases saved selections and never emits on mount or unmount.
  • Locked options (disabled) render checked when their value is in modelValue and stay focus-skipped (Tab). Because native disabled checkboxes are excluded from form submission, FormData.getAll(name) omits them.

Select-all derivation ​

Derive a mixed parent from the group's enabled option values (E) and current model (S):

ts
const on = E.filter((v) => S.includes(v)).length
const checked = E.length > 0 && on === E.length
const indeterminate = on > 0 && !checked

function setAll(next: boolean): TValue[] {
  return next
    ? [...S, ...E.filter((v) => !S.includes(v))]
    : S.filter((v) => !E.includes(v))
}

Counting enabled options only ensures clicking the select-all always transitions cleanly between checked and unchecked without getting stuck in mixed on locked choices. Bind the select-all checkbox without value and drive setAll from native @change (event.target.checked) rather than @update:model-value, so a native form reset does not trigger setAll(false) while the group restores its own baseline.

Labeling ​

Name the group with a <legend> as the first child of the default <fieldset> root, or with aria-label / aria-labelledby on the root. Note that <label for> from GhostFieldLabel cannot label a <fieldset>; keep <legend> or aria-labelledby for the group name while using GhostField per option for each checkbox's own label and description.

Keyboard, focus, and SSR ​

  • Keyboard: Native checkbox behavior only—Tab and Shift+Tab visit each enabled checkbox (including non-member checkboxes) in DOM order, Space toggles the focused checkbox, and Enter does not toggle (it submits inside a form). There is no roving focus or arrow-key navigation.
  • Focus after removal: If a focused member unmounts while the group stays mounted and focus would fall to document.body, the group moves focus after flush to the next enabled member in DOM order, or the previous enabled member if none follows.
  • SSR and hydration: Checked state, name, and disabled render deterministically from props during SSR with no generated IDs or names.

Advanced: headless composition ​

For teams building their own visual layer, import GhostCheckboxGroup, GhostCheckbox, and useGhostCheckboxGroup from @ghostvue/vue.

Headless composition Headless

Unstyled GhostCheckboxGroup and GhostCheckbox from @ghostvue/vue.

Workspace security

Model: ["audit"]

useGhostCheckboxGroup owns the selection array state, member registry, and reset logic without installing a provide/inject context. Keep GhostCheckboxGroup as the component wrapper when linking GhostCheckbox children, and customize the root host element with as (non-fieldset hosts receive role="group").

API ​

PropTypeDefaultDescription
asGhostCheckboxGroupElement"fieldset"Root host. A fieldset needs no role. Any other host gets role="group".
defaultValuereadonly TValue[]"[]"Uncontrolled seed and form-reset baseline. Shallow-copied once at setup; later prop changes and later mutation of the passed array are ignored.
disabledbooleanfalseDisables every member input natively. On a fieldset root it also sets the native disabled attribute.
invalidbooleanfalseGroup-level error hook for Field or form integration. Sets data-state="invalid" and aria-invalid="true" on the root.
modelValuereadonly TValue[]—Controlled selection. undefined is uncontrolled. [] is a defined empty selection. Accepts readonly and frozen arrays; never mutated.
namestring—Native name applied to every member input. Without a group name, members without their own name submit nothing.
SlotSlot propsDescription
default—Member checkboxes, labels, legend, descriptions, and non-member content.

@ghostvue/themes adds no props, events, or slots to the headless GhostCheckboxGroup API, which it forwards.

GhostCheckboxCard ​

PropTypeDefaultDescription
disabledbooleanfalseDisables this card. The card is also disabled when the group is.
valuestringRequiredMember value, passed to the inner checkbox. An opaque string typed by the owning group.
SlotSlot propsDescription
default—The option's accessible name. Phrasing content only.
description—Supporting detail, announced as the description. Phrasing content only.

@ghostvue/themes adds no props, events, or slots to the headless GhostCheckboxCard API, which it forwards.

See the GhostCheckboxGroup specification and the choice cards specification for the full design and compatibility contracts.