Textarea component allows users to enter text that can span multiple lines, such as a message. For shorter input, use the Input component.

Open in new tab
import { Textarea } from "@kesko/components";

export default () => <Textarea label="Label" name="message" placeholder="Placeholder" />;
import { Textarea } from "@kesko/components";

export default () => (
  <Textarea
    label="Delivery instructions"
    name="instructions"
    description="Door code, floor, or where to leave the bags."
  />
);
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack>
    <Textarea label="Review" name="review" counter maxLength={200} defaultValue="Fresh bread, friendly staff." />
    <Textarea label="Notes" name="notes" counter description="Anything the driver should know." />
  </Stack>
);
import { Textarea } from "@kesko/components";

const subtle = {
  "--k-label-text": "var(--k-color-text-dim)",
  "--k-label-weight": "var(--k-font-weight-medium)",
  "--k-label-required": "var(--k-color-status-error)",
};

export default () => <Textarea label="Custom label" name="custom" required style={subtle} />;
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack direction="row">
    <Textarea
      label="Short note"
      name="note"
      style={{ "--k-textarea-inline-size": "16rem", "--k-textarea-block-size": "6rem" }}
    />
    <Textarea label="Long message" name="long" style={{ "--k-textarea-block-size": "20rem" }} />
  </Stack>
);
import { Textarea } from "@kesko/components";

export default () => (
  <Textarea label="Message" name="message" defaultValue="Thanks for the quick delivery!" disabled />
);
import { Textarea } from "@kesko/components";

export default () => <Textarea label="Comment" hideLabel name="comment" placeholder="Write a comment" />;
import { Textarea } from "@kesko/components";

export default () => (
  <Textarea
    label="Delivery address"
    name="address"
    defaultValue={"Maija Meikäläinen\nMannerheimintie 1 A 2\n00100 Helsinki"}
    readOnly
  />
);
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack>
    <Textarea label="Reason for return" name="reason" required />
    <Textarea label="Additional details" name="details" required hideRequired />
  </Stack>
);
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack>
    <Textarea label="Resizable" name="vertical" placeholder="Drag the corner to make room" />
    <Textarea label="Fixed height" name="none" resize="none" placeholder="Stays this size" />
    <Textarea label="Grows with content" name="auto" resize="auto" placeholder="Keeps everything visible" />
  </Stack>
);
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack>
    <Textarea label="Large" size="lg" placeholder="Placeholder" />
    <Textarea label="Medium" placeholder="Placeholder" />
  </Stack>
);
import { Button, Stack, Textarea } from "@kesko/components";

export default () => (
  <form onSubmit={event => event.preventDefault()}>
    <Stack>
      <Textarea label="Feedback" name="feedback" required placeholder="What went well, what did not?" />
      <Textarea
        label="Review"
        name="review"
        defaultValue="Good"
        minLength={20}
        error="Write at least 20 characters so other customers get the picture."
      />
      <Textarea label="Message" name="message" defaultValue="Thanks for the quick delivery!" success="Message sent." />
      <Button type="submit">Submit</Button>
    </Stack>
  </form>
);

Properties #

NameDescriptionTypeDefault
label

Label for the textarea. Always provide one, even when it is hidden with hideLabel.

ReactNode—
hideLabel

Hides the label visually while keeping it available to assistive technology.

booleanfalse
description

Assistive text shown below the control, such as what to write.

ReactNode—
error

Optional error message for the textarea, shown instead of the built-in validation message. Also marks the control invalid for assistive technology.

ReactNode—
success

Optional success message for the textarea. Shown only while there is no error. A plain string is also announced to screen readers when it appears.

ReactNode—
size

The size of the textarea.

"md" | "lg""md"
resize

Controls whether the textarea is resizable. By default it is manually resizable vertically and never shrinks below its default height. Set to none to lock the height, or auto to grow as content grows.

"vertical" | "none" | "auto""vertical"
counter

Shows a count of the characters in the textarea below the control. When combined with maxLength, both the count and the limit are shown.

booleanfalse
name

The name the value is submitted under.

string—
value

The value of the control. Pair with onChange to control the field.

string—
defaultValue

The starting value of an uncontrolled field.

string—
form

The id of the form the control submits with. Only needed when the control sits outside that form.

string—
placeholder

Short hint shown while the control is empty. Not a substitute for a label.

string—
minLength

The fewest characters the value may have before the form submits.

number—
maxLength

The most characters the control accepts. Shown next to the count when counter is set.

number—
wrap

How long lines are handled. soft wraps them in the box and submits only the line breaks people typed. off never wraps, so long lines scroll sideways.

"soft" | "off"—
required

Requires a value before the form submits. Draws the marker on the label and is announced to assistive technology.

booleanfalse
hideRequired

Hides the required marker on the label while keeping required on the control. Use it when the form says once that every field is required.

booleanfalse
readOnly

Stops the value being edited while keeping the control focusable and its value submitted. Reach for disabled to drop it from the form entirely.

boolean—
disabled

Disables the control. Blocks interaction and drops the value from the submitted data.

boolean—
autoComplete

Tells the browser what the value is for, so it can offer to fill it in.

string—

Events #

NameDescriptionType
onChange

Handler called as the value changes. Fires on every keystroke.

(event: ChangeEvent<HTMLTextAreaElement>) => void
onInput

Handler called on the native input event. Fires alongside onChange; reach for it only when you need the raw event.

(event: SyntheticEvent<HTMLTextAreaElement>) => void
onSelect

Handler called when the selected text changes.

(event: SyntheticEvent<HTMLTextAreaElement>) => void
onFocus

Handler called when the control receives focus.

(event: FocusEvent<HTMLTextAreaElement>) => void
onBlur

Handler called when the control loses focus.

(event: FocusEvent<HTMLTextAreaElement>) => void

Styles #

CSS custom properties provide finer-grained control than properties. See Styling API for more details. Prefer the Properties API when it suits your need.

NameDescriptionDefault
--k-textarea-bg

Overrides the background color.

var(--k-color-bg-base)
--k-textarea-text

Overrides the text color.

var(--k-color-text-base)
--k-textarea-border

Overrides the border color in every state.

var(--k-color-border-control)
--k-textarea-radius

Overrides the border radius.

var(--k-radius-md)
--k-textarea-inline-size

Overrides the width of the field.

100%
--k-textarea-block-size

Overrides the default height, which is also the minimum height when resizing. Defaults to about five lines of text.

calc(5lh + 2 * var(--k-space-md))

Accessibility #

Textarea is built on a native <textarea> and <label>, so it behaves as expected with assistive technologies.

  • Always pass a label. A screen reader reads it as the name, and clicking it focuses the control. If there is no room for it, use hideLabel rather than leaving it out.
  • placeholder is a hint, not a description. Don’t put anything people need in order to fill in the field in the placeholder. It disappears as soon as they type. Use description for that instead.
  • Say what to write. Use description for what the text is for and how it will be used, and autoComplete where the browser can fill it in, such as street-address.
  • Leave resize on. The default lets people drag the box taller, which helps anyone reviewing a long answer. Use resize="none" only when the layout truly cannot grow, and resize="auto" when the all of the content should stay visible.
  • Show the limit, don't just enforce it. maxLength alone cuts the text silently. Pair it with counter so the count and the limit are visible and read with the field on focus.
  • Avoid disabled for validation. A disabled control leaves the tab order and cannot explain itself. Keep it enabled and let the message say what is wrong. Use readOnly for a value people need to see and copy but not edit.
  • Check contrast if you override colors. Text needs 4.5:1 against --k-textarea-bg, and --k-textarea-border needs 3:1 against the surface the field sits on. Verify with the WebAIM contrast checker.

See the accessibility guidelines and the A11Y checklist for more details.


Usage #

There are two necessary parts to using the Textarea component. The @kesko/components package and the CSS Framework are required. Everything else is optional:

npm install @kesko/components @kesko/css

Once installed, load the CSS Framework in your app’s entry point or root layout:

import "@kesko/css";

Then, you can import the Textarea:

import { Textarea } from "@kesko/components";

Projects without React can get the same styles from @kesko/css by importing the components stylesheet as well:

@import "@kesko/css";
@import "@kesko/css/components";

Resources #