Skip to content

GhostSwitch reference ​

Package: @ghostvue/vue. Status: experimental (stability policy).

Headless on/off switch. useGhostSwitch owns v-model, APG switch semantics, disabled/readonly, and form submit/reset; GhostSwitch is the thin unstyled button. Themed visual props live on @ghostvue/themes.

Generated from the component manifest. Edit the manifest or Vue source, then rebuild the docs.

All component references

Props ​

NameTypeDefaultRequiredDescription
defaultValuebooleanfalseNoInitial on/off when modelValue is omitted. Form reset restores this mounted value.
disabledbooleanfalseNoNative disabled: not focusable, not operable, and not submitted.
formstring—NoAssociates the hidden input with an external form id.
modelValueboolean—NoControlled on/off. Omit for uncontrolled mode.
namestring—NoForm field name. Submits name=value while on and enabled.
readonlybooleanfalseNoFocusable and submitted, but not user-operable. Expressed as aria-readonly.
valuestring"on"NoSubmitted string when on. Same default as a native checkbox.

Emits ​

None declared.

Models ​

PropEventTypeDescription
modelValueupdate:modelValuebooleanv-model binding for on/off.

Slots ​

NameDescription
defaultOptional inner content, usually a visible name. Prefer a label for=id or aria-label when the name should not sit inside the control. Do not put On/Off in the name.

Slot props: default ​

None declared.

Exposed members ​

NameTypeDescription
blur() => voidRemoves focus from the native button when it is mounted. No-op before mount.
checkedbooleanCurrent on/off.
elementHTMLButtonElement | nullThe native switch button after mount; null before mount and after unmount.
focus(options?: FocusOptions) => voidFocuses the native button when it is mounted and enabled. No-op before mount.
toggle() => voidUser-activation toggle. No-op when disabled or readonly.

Parts and data attributes ​

AttributeValueDescription
data-partrootThe native button element.
data-parttrackDecorative track. aria-hidden.
data-partthumbDecorative thumb inside the track. aria-hidden.
data-statecheckedSwitch is on. Pair with aria-checked=true.
data-stateuncheckedSwitch is off. Pair with aria-checked=false.

CSS variables ​

None declared.

Accessibility ​

Role: switch. APG pattern: https://www.w3.org/WAI/ARIA/apg/patterns/switch/.

Required ARIA attributes: aria-checked.

Keyboard ​

KeyActionAutomated browser test
SpaceToggle the switch when it is enabled and not readonly.GhostSwitch › toggles from pointer and keyboard, participates in forms, and has no axe violations (@ghostvue/vue)
EnterToggle the switch when it is enabled and not readonly. Implemented because the host is a native button; APG lists Enter as optional.GhostSwitch › toggles from pointer and keyboard, participates in forms, and has no axe violations (@ghostvue/vue)

Verification ​

Each category is reviewed separately. Automated keyboard and axe results do not attest manual or assistive-technology review.

CategoryStatusEvidence
Automated keyboardPassedEvery declared key maps to a Chromium browser test that CI runs and requires to pass on every commit.
Manual interactionNot reviewedNo review recorded.
Assistive technologyNot reviewedNo review recorded.

Examples ​

switch/basic ​

Example source

Basic Headless

Labeled native switch. The default state is off.

switch/composable ​

Example source

Composable Headless

Same contract as GhostSwitch, applied to a native host.

switch/ref ​

Example source

Component ref Headless

Template refs expose element, checked, toggle, focus, and blur.