Skip to Content
🎉 Coral x Panda has been released 🎉 Read the Migration Guide

TextArea

This component allows users to write or edit text.

Basic Usage

import { TextArea } from '@krakentech/coral'; <TextArea label="Text area" />

Properties

defaultValue

<TextArea label="Text area" defaultValue="Roger Nesbit" />

disabled

<TextArea label="Text area" disabled />

error / errorMessage

<TextArea label="Text area" error errorMessage="Please fill out this field" />

optional

<TextArea optional />

placeholder

<TextArea label="Text area" placeholder="Placeholder text" />

rows

<TextArea label="Text area" rows="5" />

theme

<TextArea label="Text area" theme="secondary500" />

value

const [inputValue, setInputValue] = useState('Some value'); <TextArea label="Text area" value={inputValue} /> <Button size="small" onClick={() => setInputValue('A different value')} > Change Value </Button>

Event Handlers

<TextArea label="Text area" onBlur={() => {}} onFocus={() => {}} onChange={(event) => {}} />

Responsiveness

<TextArea label="Text area" theme={{ base: "secondary500", lg: "base100" }} />

Full API

NameTypeDefault
defaultValuestring

If set, a default value will be set for the input.

disabledboolean

If true, the component will be disabled and not respond to user interactions.

false
errorboolean

If true, the component will have error styling set.

errorMessagestring

If set, the ErrorMessage component will be rendered below the input with this text.

'Invalid input'
idstring

The id of the input element. If unspecified, an id will be generated internally.

labelstring

The accessible label for the text area.

namestring

The field name used on the POST request when the form is submitted.

onBlurFocusEventHandler<HTMLTextAreaElement>

Callback fired when the text area loses user focus.

onChangeChangeEventHandler<HTMLTextAreaElement>

Callback fired each time the user types in the text area.

onFocusFocusEventHandler<HTMLTextAreaElement>

Callback fired when the text area receives user focus.

placeholderstring

Optionally displays a text hint in the field, before it is populated.

optionalboolean

Add an optional flag to the label for this field (controlled by https://coral-oe.vercel.app/?path=/docs/guides-configuration—docs#overrides-optional-indicator  optionalIndicator). This should be set to true if you have set this field to be optional in your validation schema.

false
rowsnumber

Specifies the visible number of lines in a text area.

3
valuestring | null

value should be supplied by the parent component to control the value of the TextArea input.

themeResponsiveVariant<"base100" | "secondary500">

The colourway applied to this component.

base100
attributesAttributes

This prop can be used to pass HTML attributes directly to the component. We currently allow passing data-* and aria-* attributes and the id. However, you can pass anything else with a type hack if necessary since this object is despread in to the component, without filtering its content.

Example usage:

AttributesProps: { 'id': 'close-button', 'aria-label': 'Close button', 'data-testid': 'close-button' };
refRef<HTMLTextAreaElement> | undefined

Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

keyKey | null | undefined

Design

Good to know

Choose a text area if you want to indicate to a user that they need to or can input multiple lines of text. A text area should make it clear what information is being requested and address any errors related to that info.

Why don’t we indicate mandatory fields?

It is a better user experience when forms are explicit about optional fields by labelling them so, that way the user can be reassured they can proceed without completing it. Therefore in Coral our mandatory fields are the default and optional fields are marked as such.

Why do I need to use a different text area for Hemocyanin and Siphon, they look the same?

When the text area is interacted with the label moves up to the top of the field. This label now sits within a label container which gives the illusion of the cut out at the top. This container matches the colour of the background you’re using, therefore you need to use the text area corresponding to the background colour it is going on.

Customisation

Our text area component has a single variation you can play with. Our components default with properties turned on, however you can choose to toggle on and off the optional label.

Component breakdown

  • Corner radius: 12px
  • Border: 2px
  • Input text: Body 1
  • Label container: Caption text
  • Left padding: 16px | Right padding: 80px
  • Horizontal padding: 16px | Vertical padding: 16px
Last updated on