Skip to main content

InputField

A labeled field wrapper with slots, validation, feedback, and ARIA relationships.

Package@g4rcez/componentsSectionForm Controls

Examples

Basic InputField

Wraps a native input with a label, border, and error/feedback support.

Basic
tsx
import { InputField } from "@g4rcez/components";

function BasicInputField() {
  return (
    <InputField name="username" title="Username" placeholder="Enter username" required>
      <input
        id="username"
        name="username"
        type="text"
        placeholder="Enter username"
        className="input h-input-height w-full flex-1 rounded-input-radius bg-transparent px-input-padding-x py-input-padding-y text-input-text text-foreground outline-none"
      />
    </InputField>
  );
}

With Left and Right Slots

left and right props render content inside the field border, before and after the input.

With slots
tsx
import { InputField } from "@g4rcez/components";
import { MagnifyingGlassIcon } from "@phosphor-icons/react";

function WithSlots() {
  return (
    <InputField
      name="search"
      title="Search"
      placeholder="Search..."
      left={<MagnifyingGlassIcon size={16} className="text-secondary" />}
      right={<span className="text-xs text-secondary">Ctrl+K</span>}
      required
    >
      <input
        id="search"
        name="search"
        type="search"
        placeholder="Search..."
        className="input h-input-height w-full flex-1 rounded-input-radius bg-transparent px-input-padding-x py-input-padding-y text-input-text text-foreground outline-none"
      />
    </InputField>
  );
}

Error and Info States

Pass error to show validation text. Pass info to display a tooltip next to the label.

Error & info
tsx
import { InputField } from "@g4rcez/components";

function ErrorAndInfo() {
  return (
    <div className="flex flex-col gap-4">
      <InputField
        name="email"
        title="Email"
        error="Please enter a valid email address."
        required
      >
        <input
          id="email"
          name="email"
          type="email"
          className="input h-input-height w-full flex-1 rounded-input-radius bg-transparent px-input-padding-x py-input-padding-y text-input-text text-foreground outline-none"
        />
      </InputField>
      <InputField
        name="api-key"
        title="API Key"
        info="Generate a key from your account settings."
        required
      >
        <input
          id="api-key"
          name="api-key"
          type="password"
          placeholder="sk-..."
          className="input h-input-height w-full flex-1 rounded-input-radius bg-transparent px-input-padding-x py-input-padding-y text-input-text text-foreground outline-none"
        />
      </InputField>
    </div>
  );
}

When to use InputField

Use when

Use InputField when a control needs a persistent label, hint, validation message, or slot.

Avoid when

Avoid replacing the label with placeholder text or using InputField for non-form content.

Accessibility

Keep the title or label present, connect errors and hints to the control, and let the field expose its required state.

  • Keep keyboard focus visible and follow the documented key commands.
  • Provide an accessible name and connect descriptions or errors to the control.