Input

A single-line text input.

Overview

A short piece of text: a name, an amount, a search term.

Amount

Do
R
import { Input } from "@hackcove/ui";

<Input
  prefix="R"
  inputMode="decimal"
  align="end"
  width="md"
  aria-label="Amount"
  defaultValue="49.90"
/>
An amount takes a prefix for the currency, inputMode="decimal" for the phone keypad and align="end" so the digits line up.
Don't
import { Input } from "@hackcove/ui";

<Input placeholder="R 0.00" width="md" aria-label="Amount" />
A currency typed into the placeholder is gone as soon as the person types, and nothing keeps the digits aligned.

Search

Do
import { Input } from "@hackcove/ui";

<Input
  type="search"
  aria-label="Search shops"
  placeholder="Search by name or suburb…"
  icon={
    <svg viewBox="0 0 20 20" fill="currentColor">
      <path
        fillRule="evenodd"
        d="M9 3.5a5.5 5.5 0 1 0 3.4 9.8l3.15 3.15a.75.75 0 1 0 1.06-1.06
          l-3.15-3.15A5.5 5.5 0 0 0 9 3.5Z
          m-4 5.5a4 4 0 1 1 8 0 4 4 0 0 1-8 0Z"
        clipRule="evenodd"
      />
    </svg>
  }
/>
A search box is type="search" with an icon: the browser's own look is dropped and a clear button appears once there is a value.
Don't
import { Input } from "@hackcove/ui";

<Input aria-label="Search shops" placeholder="Search by name or suburb…" />
A plain text input used for search has no icon and no way to clear it.

Usage

  • Put an Input in a Field. Without one, name it with aria-label.
  • A search box is type="search" with an icon; the clear button appears by itself.
  • prefix is short text inside the border before the value, such as a currency symbol. It is for a plain field, not one with an icon or type="search". Pair it with align="end" and inputMode="decimal" for an amount.
  • size="sm" is for a dense form or a table row.
  • width is full by default; xs, sm, md and lg are fixed widths for a short value; fill grows to the room beside other items in a row; auto is as wide as the browser makes it.
  • A paragraph is a Textarea; a choice from a list is a Select; a date is a DatePicker.

Accessibility

  • An Input is a native <input>: it takes type, inputMode, autoComplete, required, disabled and the aria-* and data-* props.
  • A type="search" field shows a "Clear search" button while it has a value; the button is labelled and is hidden when the field is disabled or read-only.
  • The icon is decorative and hidden from assistive tech.
  • The focus ring comes from the component.

API

Input

A text input. icon puts a leading icon inside the field (e.g. a search glass). prefix puts short text inside the border before the value, such as a currency symbol; it is for a plain field, not with an icon or type="search". align="end" right-aligns the value, for a numeric field. type="search" drops the browser's own search look and shows a "Clear search" button at the trailing edge while the field has a value.


align

end right-aligns the value, for a numeric field. start (default) leaves it as typed.

Type
"end" | "start"
Default
start

icon
Type
ReactNode

prefix
Type
string

size

sm is compact, text-xs with less padding, for dense forms and table rows.

Type
"sm" | "md"
Default
md

width

full (default) fills the parent; fill grows to fill the room left in a row beside other items (it can shrink to nothing, so buttons stay on the line); xs, sm, md, lg are fixed; auto is as wide as its content.

Type
"auto" | "sm" | "md" | "lg" | "xs" | "fill" | "full"
Default
full