GkField
Wraps a single form control: label (optional), default slot for GkInput (or future controls), an optional hint, and an error string with role="alert".
When to use
Use for every labeled control in a form so ids, aria-describedby, and error text stay consistent.
Live Examples
Basic
Submit runs simple validation and sets the field error string.
Best practice: Keep one control per GkField so label and aria-describedby stay unambiguous.
Static error
Pass :error from your validation layer to show invalid state and the alert region.
Use an address with @.
Visually hidden label
label-sr-only keeps a proper label for assistive tech when the visible heading lives elsewhere.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Visible label text |
error | string | — | Error message; sets invalid state on child input |
hint | string | — | Helper text under the control; hidden while error is set |
labelSrOnly | boolean | false | Visually hide label but keep for screen readers |
Slots
| Slot | Description |
|---|---|
default | The input or control (e.g. GkInput) |
Provide / inject
GkField uses useFieldIds() internally, then provides context for child controls (inputId, errorId, errorMessage, hintId, hintMessage). See Composables for headless usage without GkField. You rarely need to use the injection key directly; import GK_FIELD from god-kit/vue only for advanced cases.
Hint and error
<GkField label="Email" hint="We never share it.">
<GkInput v-model="email" type="email" />
</GkField>An error replaces the hint rather than stacking with it, so the control's aria-describedby always points at exactly one message and screen readers announce the error instead of stale help text.
Examples
Each scenario under Live Examples includes a copyable Vue snippet.
Accessibility notes
- Keep one control per field wrapper so label/id relationships remain clear.
hintanderrorare mutually exclusive by design: only one is rendered, and it is the onearia-describedbyreferences.- Use
labelSrOnlyonly when visible label text exists elsewhere in nearby UI context.
