Skip to content

GkField

Wraps a single form control: label (optional), default slot for GkInput (or future controls), 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.

Visually hidden label

label-sr-only keeps a proper label for assistive tech when the visible heading lives elsewhere.

API

Props

PropTypeDefaultDescription
labelstringVisible label text
errorstringError message; sets invalid state on child input
labelSrOnlybooleanfalseVisually hide label but keep for screen readers

Slots

SlotDescription
defaultThe input or control (e.g. GkInput)

Provide / inject

GkField uses useFieldIds() internally, then provides context for child GkInput (inputId, errorId, errorMessage). 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.

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.
  • Use labelSrOnly only when visible label text exists elsewhere in nearby UI context.

Released under the MIT License.