Text area API
Import
Section titled “Import”import { TextArea } from '@cimpress-ui/react';Controlled/uncontrolled usage
Section titled “Controlled/uncontrolled usage”This component can be used in a controlled or uncontrolled way.
In the controlled way, this component doesn’t maintain its own internal state, and its value is provided by the parent component. Use the controlled way when you need to be able to change the state of this component in other parts of your application.
In the uncontrolled way, this component maintains its own internal state, and can optionally notify the parent component when its internal state changes. Use the uncontrolled way when you don’t need to change the state of this component in other parts of your application.
import { TextArea, Stack } from '@cimpress-ui/react';import { useState } from 'react';
export default function Demo() { const [feedback, setFeedback] = useState('Everything is fine.');
return ( <Stack gap={32}> <TextArea label="Feedback (controlled)" rows={3} value={feedback} onChange={setFeedback} /> <TextArea label="Feedback (uncontrolled)" rows={3} defaultValue="Everything is fine." /> </Stack> );}Imperative API
Section titled “Imperative API”This component exposes an imperative API through the apiRef prop. This API allows triggering behaviors that can’t be expressed by props.
import { Button, Stack, TextArea, type TextAreaApi } from '@cimpress-ui/react';import { useRef } from 'react';
export default function Demo() { const apiRef = useRef<TextAreaApi>(null);
return ( <Stack gap={16}> <TextArea label="Feedback" rows={3} defaultValue="Everything is fine." apiRef={apiRef} />
<Stack gap={16} direction={{ md: 'horizontal' }}> <Button onPress={() => apiRef.current?.focus()}>Focus</Button> <Button onPress={() => apiRef.current?.select()}>Select contents</Button> </Stack> </Stack> );}Accessibility notes
Section titled “Accessibility notes”TextArea requires a textual label to remain accessible to assistive technologies. See our accessibility guide for more details.
Text area can integrate with native HTML forms. See our forms guide to learn how to work with forms.
API reference
Section titled “API reference”TextArea
Section titled “TextArea”Allows users to enter multiple lines of text with a keyboard.
- Ref<HTMLDivElement>
-
The
reftype for this component.
TextAreaProps
- 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters' | (string & ({ }))
autoCapitalize
Section titled “ autoCapitalize ” -
Controls whether inputted text is automatically capitalized. See MDN.
- 'off' | 'on'
autoCorrect
Section titled “ autoCorrect ” -
Controls whether inputted text can be autocorrected by the browser. See MDN.
- number
-
Controls how many lines of text are visible by default. See MDN.
- boolean
spellCheck
Section titled “ spellCheck ” -
Controls whether the inputted text may be checked for spelling errors. See MDN.
- 'soft' | 'hard'
- Defaults to 'soft' .
Controls how the inputted text will be wrapped for form submission. See MDN.
- string
-
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
label
Section titled “ label ” -
The content to display as the label.
- string
aria-label
Section titled “ aria-label ” -
Defines a string value that labels the current element.
- string
aria-labelledby
Section titled “ aria-labelledby ” -
Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “ aria-describedby ” -
Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “ aria-details ” -
Identifies the element (or elements) that provide a detailed, extended description for the object.
- string
-
The
<form>element to associate the input with. The value of this attribute must be the id of a<form>in the same document. See MDN. - string
-
The name of the input element, used when submitting an HTML form. See MDN.
- string
description
Section titled “ description ” -
A description for the field. Provides a hint such as specific requirements for what to choose.
- FieldError
error
Section titled “ error ” -
An error message for the field.
- (value: string) => string | true | string[] | undefined
validate
Section titled “ validate ” -
A function that returns an error message (or
true) if a given value is invalid. Validation errors are displayed to the user when the form is submitted. For real-time validation, use theerrorprop instead. - string
placeholder
Section titled “ placeholder ” -
The placeholder text displayed in the input field.
- RefObject<TextAreaApi | null>
apiRef
Section titled “ apiRef ” -
A React ref that allows access to the imperative API of this component.
- string
autoComplete
Section titled “ autoComplete ” -
Describes the type of autocomplete functionality the input should provide if any. See MDN.
- number
maxLength
Section titled “ maxLength ” -
The maximum number of characters supported by the input. See MDN.
- number
minLength
Section titled “ minLength ” -
The minimum number of characters required by the input. See MDN.
- 'search' | (string & ({ })) | 'text' | 'tel' | 'url' | 'email' | 'password'
- Defaults to 'text' .
The type of input to render. See MDN.
- 'search' | 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal'
inputMode
Section titled “ inputMode ” -
Hints at the type of data that might be entered by the user while editing the element or its contents. See MDN.
- (e: KeyboardEvent) => void
onKeyDown
Section titled “ onKeyDown ” -
Handler that is called when a key is pressed.
- (e: FocusEvent<HTMLInputElement>) => void
onFocus
Section titled “ onFocus ” -
Handler that is called when the element receives focus.
- (e: FocusEvent<HTMLInputElement>) => void
onBlur
Section titled “ onBlur ” -
Handler that is called when the element loses focus.
- boolean
autoFocus
Section titled “ autoFocus ” -
Whether the element should receive focus on render.
- boolean
isRequired
Section titled “ isRequired ” -
Whether user input is required on the input before form submission.
- boolean
isDisabled
Section titled “ isDisabled ” -
Whether the input is disabled.
- boolean
isReadOnly
Section titled “ isReadOnly ” -
Whether the input can be selected but not changed by the user.
- string
value
Section titled “ value ” -
The current value (controlled).
- string
defaultValue
Section titled “ defaultValue ” -
The default value (uncontrolled).
- (value: string) => void
onChange
Section titled “ onChange ” -
Handler that is called when the value changes.
- boolean
isInvalid
Section titled “ isInvalid ” -
Whether the value is invalid.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.