Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

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.

Uncontrolled

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:

UsageLink to "Usage"

tsx
Copy
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.

Clear button

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.

Error and disabled

OptionsLink to "Options"

  • variant: outline (default) or soft (tinted, borderless until focus).
  • size: xs, sm, md or lg. Heights match Button and Select. xs is a 20px field with smaller text and icons, and xs clear 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.
  • iconStart and iconEnd: icons at either edge, flipped in right-to-left layouts.
  • addonStart and addonEnd: 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, autoComplete and inputMode pass through.

PropsLink to "Props"

Every prop of TextField
PropWhat it doesTypeDefault
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() and required validation. 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.

ts
Copy
createTheme({ components: { textField: { radius: "10px", paddingInline: "14px" } } });

SearchField · TextArea · Select · IconButton

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog