Skip to main content

TextField and TextArea

import { TextField, TextArea } from "@study/ui"

A field with a label above it, optionally a hint below it and an error when something does not fit.

Result
Loading...
Live Editor
function Example() {
  const [title, setTitle] = useState("");
  return (
    <div className="ui-stack" style={{ maxWidth: 420 }}>
      <TextField
        label="Deadline title"
        placeholder="e.g. Submit exercise sheet 5"
        value={title}
        onChange={(e) => setTitle(e.target.value)}
        error={title.length > 60 ? "At most 60 characters." : undefined}
        hint="Shown like this in the calendar and on Today."
      />
      <TextArea label="Note" placeholder="What you want to remember …" />
    </div>
  );
}

Variants and states​

Light

MB

At least 10 characters.

Dark

MB

At least 10 characters.

When to use​

✓ DoThe label says what goes in; the placeholder shows an example.
✗ Don'tOnly a placeholder as a label – it disappears while typing.
  • hideLabel only when the purpose is clear from the surroundings (e.g. the "Add task" row in a list).
  • Show errors only once someone has left the field or submitted – not on the first key press.
  • For searches SearchField, for choosing from a list Select.
  • TextArea grows with its content up to half the window height.

Props​

Plus all attributes of an <input> or <textarea>.

PropTypeDefaultMeaning
label *ReactNode–What belongs in the field. Always given; `hideLabel` hides it from the eye only.
errorReactNode–What is wrong with the value; marks the field invalid.
hideLabelboolean–
hintReactNode–A short help below the field.
iconenum–An icon at the start of the field.
refRef<HTMLInputElement>–
size"md" | "lg"md
trailingReactNode–Something at the end inside the field, e.g. a unit or an `IconButton`.
PropTypeDefaultMeaning
label *ReactNode–What belongs in the field. Always given; `hideLabel` hides it from the eye only.
errorReactNode–What is wrong with the value; marks the field invalid.
hideLabelboolean–
hintReactNode–A short help below the field.
refRef<HTMLTextAreaElement>–

Accessibility​

  • Label, hint and error are connected to the field through for, aria-describedby and aria-invalid.
  • Text in fields is 16 px – so the iPhone does not zoom.
  • Errors are there as text, not only as a red border.