TextField
A text input with a label, help text and a validation message. Set multiline for a text area that grows with its content.
import {TextField} from 'alinea/components'
export function TextFieldExample() {
return (
<TextField
label="Title"
defaultValue="Summer collection"
style={{width: 280}}
/>
)
}States
description tells editors what to enter, error shows a validation message instead and marks the input as invalid. Required fields show a marker next to their label, read-only fields can still be selected and copied.
import {TextField} from 'alinea/components'
export function TextFieldStatesExample() {
return (
<div style={{display: 'grid', gap: 16, width: 280}}>
<TextField
label="Slug"
description="Used in the page URL"
defaultValue="linen-shirt"
/>
<TextField label="Title" required error="A title is required" />
<TextField label="Author" defaultValue="Anna Peeters" disabled />
<TextField label="Entry id" defaultValue="2mXhVzR4" readOnly />
</div>
)
}Multiline
A multiline field starts at rows lines and grows as editors type, up to maxRows lines when you set it, then it scrolls.
import {TextField} from 'alinea/components'
export function TextFieldMultilineExample() {
return (
<TextField
label="Description"
multiline
rows={4}
maxRows={8}
defaultValue="A relaxed shirt in washed linen that softens with every wear."
style={{width: 300}}
/>
)
}Icons
startIcon and endIcon render inside the input, before and after the text.
import {TextField} from 'alinea/components'
import {
IcRoundLink,
IcRoundOpenInNew,
IcRoundSearch
} from 'alinea/dashboard/icons'
export function TextFieldIconsExample() {
return (
<div style={{display: 'grid', gap: 16, width: 280}}>
<TextField
aria-label="Search products"
placeholder="Search products"
startIcon={IcRoundSearch}
/>
<TextField
label="Website"
type="url"
defaultValue="https://oakandloom.com"
startIcon={IcRoundLink}
endIcon={IcRoundOpenInNew}
/>
</div>
)
}Native input attributes
type, name, autoComplete, inputMode, pattern, minLength and maxLength are passed to the input. inputMode picks the virtual keyboard on touch devices, eg. numeric for a code, and pattern is a regular expression the value must match, checked when the field is in a Form.
Props
numeric for a codeAlso accepts className and style, id and aria-* labelling attributes and data-* attributes.
Accessibility
The label, description and error are linked to the input, so screen readers announce them together. An error sets aria-invalid on the input.