Input
A single-line text input.
Overview
A short piece of text: a name, an amount, a search term.
Amount
import { Input } from "@hackcove/ui";
<Input
prefix="R"
inputMode="decimal"
align="end"
width="md"
aria-label="Amount"
defaultValue="49.90"
/>prefix for the currency, inputMode="decimal" for the phone keypad and align="end" so the digits line up.import { Input } from "@hackcove/ui";
<Input placeholder="R 0.00" width="md" aria-label="Amount" />
Search
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>
}
/>type="search" with an icon: the browser's own look is dropped and a clear button appears once there is a value.import { Input } from "@hackcove/ui";
<Input aria-label="Search shops" placeholder="Search by name or suburb…" />
Usage
- Put an
Inputin aField. Without one, name it witharia-label. - A search box is
type="search"with anicon; the clear button appears by itself. prefixis short text inside the border before the value, such as a currency symbol. It is for a plain field, not one with aniconortype="search". Pair it withalign="end"andinputMode="decimal"for an amount.size="sm"is for a dense form or a table row.widthisfullby default;xs,sm,mdandlgare fixed widths for a short value;fillgrows to the room beside other items in a row;autois as wide as the browser makes it.- A paragraph is a
Textarea; a choice from a list is aSelect; a date is aDatePicker.
Accessibility
- An
Inputis a native<input>: it takestype,inputMode,autoComplete,required,disabledand thearia-*anddata-*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
iconis 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.
alignend 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
sizesm is compact, text-xs with less padding, for dense forms and table rows.
- Type
"sm" | "md"- Default
md
widthfull (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