Components / Controls
TextField
Single-line text input with a label, description, error, optional icons and an optional clear button. For several lines use TextArea; for search use SearchField.
When to useLink to "When to use"
- Names, emails, URLs, phone numbers, passwords and numbers.
- Any form field that needs a visible label with help or error text.
Use something else when:
- the text runs over several lines: TextArea
- the field is a search box: SearchField
- the user picks from a list: Select
UsageLink to "Usage"
import { TextField } from "@arshad-shah/cynosure";
import { mail } from "@arshad-shah/cynosure/icons";
<TextField label="Email" type="email" name="email" required iconStart={mail} clearable />
<TextField label="Name" value={name} onChange={setName} error={nameError} />
<TextField label="Token" type="password" description="Stored locally" />onChange receives the string value. Use value for controlled state or defaultValue for uncontrolled. type is one of text (default), email, url, tel, password, number or search. With search, the browser's own search decorations are hidden: use clearable for a clear button.
Clear buttonLink to "Clear button"
clearable shows a clear button while the field has a value. It is hidden when the field is disabled. Change its accessible name with labels.clear.
Errors and disabledLink to "Errors and disabled"
error marks the field invalid (aria-invalid) and shows the message with the field. description adds help text.
OptionsLink to "Options"
variant:outline(default) orsoft(tinted, borderless until focus).size:xs,sm,mdorlg. Heights match Button and Select.xsis a 20px field with smaller text and icons, andxsclear and reveal buttons, for dense desktop chrome. The transparent input reaches past the field's edges, so it is still 24px to press (44px on coarse pointers) while the field looks 20px. Addons keep their own size.iconStartandiconEnd: icons at either edge, flipped in right-to-left layouts.addonStartandaddonEnd: controls inside the field before or after the input (ColorField's swatch button, NumberField's steppers).labelHidden: hides the label visually while it still names the field. Prefer a visible label.- Native input attributes such as
name,required,readOnly,maxLength,autoCompleteandinputModepass through.
PropsLink to "Props"
| Prop | What it does | Type | Default |
|---|---|---|---|
labelRequired | The field's label and accessible name. | ReactNode | |
labelHidden | Visually hide the label (it still names the control). Prefer visible labels. | boolean | |
description | Help text shown below the field. | ReactNode | |
error | Error message shown below the field; it is announced and marks the field invalid. | ReactNode | |
value | The text (controlled). | string | |
defaultValue | Starting text when uncontrolled. | string | |
onChange | Called with the new text on every edit. | ((value: string) => void) | |
type | The native input type. Default "text". | "number" | "search" | "text" | "email" | "url" | "tel" | "password" | "text" |
size | Field height and text size. Default "md". xs (about 20px) is for dense desktop chrome: the input still reaches 24px to press (44px on coarse pointers), and the clear and reveal buttons shrink with it. Its label is set as for sm. Addons keep their own size. | DenseSize | "md" |
variant | outline (default) or soft (tinted, borderless until focus). | "soft" | "outline" | |
iconStart | Icon shown before the input. | IconData | |
iconEnd | Icon shown at the end of the field, after the input and its clear or reveal button. | IconData | |
clearable | Shows a clear button while the field has a value. | boolean | |
addonStart | Controls inside the field's start, before the input (ColorField's swatch button). | ReactNode | |
addonEnd | Controls inside the field's end, after the input (NumberField's steppers). | ReactNode | |
labels | Replace the built-in English text: the names of the clear, show and hide buttons. | { clear?: string; show?: string; hide?: string; } | |
revealable | With type="password": a button to show and hide the value (API keys, tokens, passwords). | boolean | |
className | Added to the root element, for layout. | string | |
style | Layout only. | CSSProperties | |
boxRef | The field's box (the input with its icons, addons and buttons), for a list or popover that drops from the whole field (Combobox, TagInput). Use it to measure or anchor; restyle through tokens, not its class. | Ref<HTMLDivElement> | |
data-testid | Test id, set on the native input. | string | |
layout | stack puts the label above the control and the description and error below it. split puts the label and description at the start and the control at the end of one row (a settings row); when the field is too narrow for both, the control moves under the text. Default "stack". | "stack" | "split" | "stack" |
width | Width of the control, so the controls of a column of fields line up: "sm", "md" and "lg" are the --cy-field-control-width-* tokens (never wider than the field), "full" is the whole field. Default: the control's own width (the whole field in the stacked layout for TextField and the other fields). | FieldWidth |
Generated from the type definitions in @arshad-shah/cynosure 0.5.0.
Behaviour and accessibilityLink to "Behaviour and accessibility"
- Label, description and error are linked to the input through
Field. - Forms: works with
FormData,form.reset()andrequiredvalidation. The clear button syncs after reset. - Clear button: an IconButton that clears the value and returns focus to the input.
- Refs: the ref points at the input element.
ThemingLink to "Theming"
Tokens: --cy-text-field-{height-xs,height-sm,height-md,height-lg,radius,padding-inline,padding-inline-xs,bg,border,soft-bg}, and --cy-text-field-numeric, the typed text's font-variant-numeric (tabular-nums in DateField, NumberField and TimeField). The border, background, radius and read-only fill fall back to Field's shared skin, --cy-field-control-{border,bg,radius,sunken-bg}, which HotkeyField's box reads too.
createTheme({ components: { textField: { radius: "10px", paddingInline: "14px" } } });RelatedLink to "Related"
SearchField · TextArea · Select · IconButton
These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.