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.
Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
defaultValue | boolean | false | No | Initial on/off when modelValue is omitted. Form reset restores this mounted value. |
disabled | boolean | false | No | Native disabled: not focusable, not operable, and not submitted. |
form | string | — | No | Associates the hidden input with an external form id. |
modelValue | boolean | — | No | Controlled on/off. Omit for uncontrolled mode. |
name | string | — | No | Form field name. Submits name=value while on and enabled. |
readonly | boolean | false | No | Focusable and submitted, but not user-operable. Expressed as aria-readonly. |
value | string | "on" | No | Submitted string when on. Same default as a native checkbox. |
Emits
None declared.
Models
| Prop | Event | Type | Description |
|---|---|---|---|
modelValue | update:modelValue | boolean | v-model binding for on/off. |
Slots
| Name | Description |
|---|---|
default | Optional 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
| Name | Type | Description |
|---|---|---|
blur | () => void | Removes focus from the native button when it is mounted. No-op before mount. |
checked | boolean | Current on/off. |
element | HTMLButtonElement | null | The native switch button after mount; null before mount and after unmount. |
focus | (options?: FocusOptions) => void | Focuses the native button when it is mounted and enabled. No-op before mount. |
toggle | () => void | User-activation toggle. No-op when disabled or readonly. |
Parts and data attributes
| Attribute | Value | Description |
|---|---|---|
data-part | root | The native button element. |
data-part | track | Decorative track. aria-hidden. |
data-part | thumb | Decorative thumb inside the track. aria-hidden. |
data-state | checked | Switch is on. Pair with aria-checked=true. |
data-state | unchecked | Switch 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
| Key | Action | Automated browser test |
|---|---|---|
Space | Toggle 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) |
Enter | Toggle 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.
| Category | Status | Evidence |
|---|---|---|
| Automated keyboard | Passed | Every declared key maps to a Chromium browser test that CI runs and requires to pass on every commit. |
| Manual interaction | Not reviewed | No review recorded. |
| Assistive technology | Not reviewed | No review recorded. |
Examples
switch/basic
Labeled native switch. The default state is off.
switch/composable
Same contract as GhostSwitch, applied to a native host.
switch/ref
Template refs expose element, checked, toggle, focus, and blur.