Components · engine.field · version 0.1.0

Field

Gives one control a visible label, a description and an error message, and relates them to it.

Preview

Every variant in every state, drawn by the same definition that the Figma sync and the tests use.

field in every variant and state
Componentrestinvalid
field
Description
DescriptionError message

Install

npm install @uiuxengine/react

Components come from npm and stay identical to their definition and their Figma component. See Installation.

Usage

import { Field, Input } from "@uiuxengine/react";

export function Example() {
  return (
    <Field
      label="Label"
      description="Description"
      error="Error message"
      control={<Input placeholder="Placeholder" />}
    />
  );
}

Guidelines

  • Use a field for every input or select that has a visible label.
  • Keep the label short. Put instructions and formats in the description.
  • Set invalid and error together while the host shows why the value is wrong. Say how to fix it.

Props

PropTypeDefaultDescription
label requiredtext, up to 120—Names the control.
descriptiontext, up to 300—Help shown under the control.
errortext, up to 300—Why the value is wrong, shown while invalid.
invalidbooleanfalseMarks the control as invalid and shows the error.

Slots

SlotTakesDescription
controlengine.input, engine.selectThe control the field names.

Accessibility

  • Renders a native <div> with the role generic.
  • Its label part names the control in control.
  • Its description and error, when shown, describe it.
  • invalid is announced on it as aria-invalid.

As a spec

Agents describe interfaces as JSON specs. A spec renders only after it validates against the installed contracts, the approved icons and the host's actions. Edit it to see.

Description

No actions yet.

JSON Schema of the props
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:uiuxengine:component:engine.field@0.1.0",
  "title": "field",
  "description": "Gives one control a visible label, a description and an error message, and relates them to it.",
  "type": "object",
  "properties": {
    "label": {
      "description": "Names the control.",
      "type": "string",
      "maxLength": 120
    },
    "description": {
      "description": "Help shown under the control.",
      "type": "string",
      "maxLength": 300
    },
    "error": {
      "description": "Why the value is wrong, shown while invalid.",
      "type": "string",
      "maxLength": 300
    },
    "invalid": {
      "description": "Marks the control as invalid and shows the error.",
      "type": "boolean",
      "default": false
    },
    "control": {
      "description": "The control the field names.",
      "type": "object",
      "properties": {
        "component": {
          "enum": [
            "engine.input",
            "engine.select"
          ]
        },
        "props": {
          "type": "object"
        }
      },
      "required": [
        "component"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "label",
    "control"
  ],
  "additionalProperties": false,
  "$defs": {
    "iconRef": {
      "type": "object",
      "description": "A reference to an icon in the host's approved catalog.",
      "properties": {
        "type": {
          "const": "icon"
        },
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "style": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "weight": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        }
      },
      "required": [
        "type",
        "id"
      ],
      "additionalProperties": false
    }
  }
}