GhostField
GhostField connects a single control with its label, description, and validation message. Start with the compound parts from @ghostvue/themes for the themed stack.
Workspace profile
Form composition with required, invalid, textarea, and disabled GhostField rows.
The form starts with an invalid Support email. Press Enter in the field to try saving. Focus stays on the invalid control. Enter team@company.com. The error clears and the hint stays associated. Press Enter again to see the Profile saved. confirmation. The disabled organization ID stays outside the tab order.
Themed stack
Default vertical spacing from @ghostvue/themes.
Spread the GhostFieldControl slot props onto the control to give it the generated ID, state flags, and associated description.
Invalid and required
Use required for a native constraint and invalid for your form’s validation state. In the profile form above, the error renders only while the email is invalid. The description remains linked as the user edits the address.
Textarea
Use the same label, description, and control parts with GhostTextarea. The profile form uses them for Bio. See the release notes composer for a full textarea workflow.
Wrapping checkbox label
Toggle a weekly digest with a themed checkbox and its wrapping label.
Set associate="wrap" on GhostFieldLabel when the control lives inside the label. The default associate="reference" sets for to the generated control id.
Group related fields
Group labelled inputs in a native fieldset and inspect the submitted address.
The Billing address legend names the native fieldset. Each input keeps its own label and hint. Open Example settings to disable the section or show a group or city error. Save address displays the entries from the native form. Disabling the fieldset preserves typed values and omits them from submission. An enabled control inside its first legend still participates.
For a single radio question, put one legend directly inside the radio group. Arrow keys select the value submitted under cadence.
<GhostRadioGroup as="fieldset" name="cadence" default-value="annual">
<legend>Billing cadence</legend>
<label><GhostRadioGroupItem value="monthly" /> Monthly</label>
<label><GhostRadioGroupItem value="annual" /> Annual</label>
</GhostRadioGroup>Using GhostField inside GhostForm
Pass a canonical dot-path name prop when composing GhostField inside GhostForm so invalid state, <GhostFieldError /> text, and blur/change tracking wire automatically while standalone fields (outside GhostForm, or inside GhostForm without name) stay prop-driven. Explicit :invalid="true" or :invalid="false" on GhostField always overrides form state.
A GhostDatePickerInput inside a field also reports its own errors there, with or without a form: a rejected date marks the field invalid and shows the picker's reason in <GhostFieldError />.
Customize with headless fields
Import the field parts from @ghostvue/vue for your own layout or styles.
Basic labeled input
Label, hint, and control id wiring for GhostInput.
Headless validation and textarea
Required filter with error copy and aria-invalid.
GhostTextarea composed with description.
Headless address fieldset
For headless styling, keep the fieldset and legend and import the field parts from @ghostvue/vue. A plain labelled native input can also receive the field control slot props.
The same native fieldset recipe with headless GhostField parts and consumer-owned styles.
Styling hooks
Parts expose data-part="label" | "description" | "error" | "control". Themed CSS stacks children with spacing tokens under .ghost-theme or .ghost-themed-scope.
Composable
useGhostField returns SSR-stable ids and state for custom layouts that still use the field relationship contract.
API
GhostField
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Propagates disabled semantics to the control. |
id | string | — | Optional control id override for label association. |
invalid | boolean | — | Propagates invalid semantics and root data-state. |
name | string | — | Canonical dot-path key associating this field with an ancestor GhostForm. |
required | boolean | false | Propagates required semantics to the control. |
| Slot | Slot props | Description |
|---|---|---|
default | dirty: boolean, error: string | undefined, errors: readonly string[], invalid: boolean, touched: boolean | Field parts (label, description, control, error) in consumer-chosen order. |
@ghostvue/themes adds no props, events, or slots to the headless GhostField API, which it forwards.
Root: class ghost-field, data-ghost-field, data-part="root", optional data-state="invalid" | "disabled".
GhostFieldLabel
| Prop | Type | Default | Description |
|---|---|---|---|
as | GhostFieldLabelElement | "label" | Label element. |
associate | GhostFieldLabelAssociate | "reference" | for association or nested labeling. |
required | boolean | false | Shows the required marker with root required. |
showRequired | boolean | true | Toggles the visual required indicator. |
| Slot | Slot props | Description |
|---|---|---|
default | — | Primary content. |
GhostFieldDescription
Default element p with stable id for aria-describedby.
GhostFieldError
Default element span with role="alert" when the slot has content.
GhostFieldControl
Scoped slot props:
| Name | Type | Description |
|---|---|---|
id | string | Shared control id. |
disabled | boolean | From root. |
invalid | boolean | From root. |
required | boolean | From root. |
aria-describedby | string | Description and error ids when mounted. |
aria-invalid | boolean | Present when root invalid is true. |
Accessibility
- Name the control with
GhostFieldLabel(foror wrap). - Hints and errors are linked with
aria-describedby. - Invalid uses native
aria-invalid/invalidon library controls. - Field does not trap focus or handle keyboard input; the control does.