Text Area
A multi-line input field in a user interface that allows users to enter larger amounts of text. It is often used in forms where users need to provide lengthy information, such as comments, reviews, or descriptions.
import {QTextArea} from "@qui/react"
Examples
Showcase
Customize size using the size property.
Small (s)
Medium (m)
Large (l)
import {ReactNode} from "react"import {QTextArea} from "@qui/react"export default function Showcase(): ReactNode {return (<div className="grid grid-cols-[160px,auto] items-center justify-center gap-4 py-1"><div className="text-primary q-font-heading-xs">Small (s)</div><QTextAreaclassName="flex overflow-auto"placeholder="Start Typing..."size="s"/><div className="text-primary q-font-heading-xs">Medium (m)</div><QTextAreaclassName="flex overflow-auto"placeholder="Start Typing..."size="m"/><div className="text-primary q-font-heading-xs">Large (l)</div><QTextAreaclassName="flex overflow-auto"placeholder="Start Typing..."size="l"/></div>)}
Customization
Use the label, hint, and error props to describe the element.
Supply counter to display the current character count.
Error
import {ReactNode} from "react"import {QTextArea} from "@qui/react"export default function Customization(): ReactNode {return (<div className="grid justify-center gap-y-5"><div className="flex overflow-auto"><QTextAreacounterhint="Hint"label="Label"placeholder="Start Typing..."wrap="hard"/></div><div className="flex overflow-auto"><QTextAreacounterhint={<span className="text-primary q-font-metadata-sm">Custom Hint</span>}label={<span className="text-primary q-font-heading-xxs">Custom Label</span>}placeholder="Start Typing..."wrap="hard"/></div><div className="flex overflow-auto"><QTextAreacountererror="Error"label="Label"placeholder="Start Typing..."wrap="hard"/></div></div>)}
States
Supply disabled or readOnly to disable interactions.
Disabled
Error
This is a required field
Read Only
import {ReactNode} from "react"import {QTextArea} from "@qui/react"export default function Showcase(): ReactNode {return (<div className="grid grid-cols-[160px,auto] items-center justify-center gap-4 py-1"><div className="text-primary q-font-heading-xs">Disabled</div><div className="flex overflow-auto"><QTextArea disabled label="Label" placeholder="Start Typing..." /></div><div className="text-primary q-font-heading-xs">Error</div><div className="flex overflow-auto"><QTextAreaerror="This is a required field"label="About"placeholder="Write about yourself..."/></div><div className="text-primary q-font-heading-xs">Read Only</div><div className="flex overflow-auto"><QTextArea label="Label" placeholder="Start Typing..." readOnly /></div></div>)}
Input Customization
Use inputProps to pass properties to the underlying <input>
element. The following textarea features a maximum of 15 characters or 10 rows.
import {ReactNode} from "react"import {QTextArea} from "@qui/react"export default function InputProps(): ReactNode {return (<div className="flex overflow-auto"><QTextAreacounterinputProps={{cols: 50, rows: 10}}label="Label"placeholder="Start Typing..."/></div>)}
Controlled
The component can be controlled or uncontrolled.
When you supply the onChange and value props, the component is controlled
. Otherwise, the component is uncontrolled
and the value is tracked internally.
Learn more about controlled and uncontrolled components in the related React Documentation.
import {ReactNode, useState} from "react"import {QTextArea} from "@qui/react"export default function Controlled(): ReactNode {const [value, setValue] = useState("foo")return (<div className="grid justify-center gap-y-5"><div className="flex overflow-auto"><QTextAreahint="Hint"label="Controlled"onChange={(event, value) => {setValue(value)}}placeholder="Start Typing..."value={value}/></div><div className="flex overflow-auto"><QTextAreadefaultValue="bar"hint="Hint"label="Uncontrolled"placeholder="Start Typing..."/></div></div>)}
API
Props
Name & Description | Option(s) | Default |
---|---|---|
The component used for the root node. It can be a React component or
element. |
| 'div' |
If true , React will focus the component on mount. |
| |
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element. |
| |
Maximum number of characters for this text area element. |
| false |
Default input value. |
| |
If true, the component will not be interactive and will appear dimmed. |
| false |
Optional error, triggers the invalid style variant if supplied. This element
is automatically associated with the component's input element for optimal
accessibility. | ReactNode | |
Specifies the id of the <form> this input belongs to. If omitted, it’s the
closest parent form. |
| |
Optional hint describing the element. This element is automatically associated
with the component's input element for optimal accessibility. | ReactNode | |
Controlled id. If omitted, a unique identifier will be automatically generated
for error, label, and hint accessibility. |
| |
attributes
applied to the input element. |
| {} |
Pass a ref to the textarea element. |
| |
Optional label describing the element. Recommended. This element is
automatically associated with the component's input element for optimal
accessibility. | ReactNode | |
Specifies the name for this input that’s submitted with the form. |
| |
An Event handler function. Fires when the input element loses focus. |
| |
Callback fired when the input value changes.
|
| |
An Event handler function. Fires when the input element gains focus. |
| |
HTML placeholder attribute. |
| |
If true, the component is not editable by the user. |
| false |
HTML resize attribute. |
| "both" |
Size of the element, label, hint, and error messages. When these properties
are supplied as templates, size styles are omitted. |
| |
The style global attribute
contains CSS styling
declarations to be applied to the element. | CSSProperties | |
Controlled input value. |
| |
HTML wrap attribute. |
| "soft" |
Type
| ElementType| ComponentType
Default
'div'
Description
The component used for the root node. It can be a React component or
element.
Type
boolean
Description
If
true
, React will focus the component on mount.Type
string
Description
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element.
Type
boolean
Default
false
Description
Maximum number of characters for this text area element.
Type
string
Description
Default input value.
Type
boolean
Default
false
Description
If true, the component will not be interactive and will appear dimmed.
Type
ReactNode
Description
Optional error, triggers the invalid style variant if supplied. This element
is automatically associated with the component's input element for optimal
accessibility.
Type
string
Description
Specifies the id of the
<form>
this input belongs to. If omitted, it’s the
closest parent form.Type
ReactNode
Description
Optional hint describing the element. This element is automatically associated
with the component's input element for optimal accessibility.
Type
string
Description
Controlled id. If omitted, a unique identifier will be automatically generated
for error, label, and hint accessibility.
Type
TextareaHTMLAttributes<HTMLTextAreaElement>
Default
{}
Description
attributes
applied to the
input
element.Type
Ref<HTMLTextAreaElement>
Description
Pass a ref to the textarea element.
Type
ReactNode
Description
Optional label describing the element. Recommended. This element is
automatically associated with the component's input element for optimal
accessibility.
Type
string
Description
Specifies the name for this input that’s submitted with the form.
Type
FocusEventHandler<HTMLTextAreaElement>
Description
An Event handler function. Fires when the input element loses focus.
Type
(event: SyntheticEvent,value: T,) => void
Description
Callback fired when the input value changes.
- eventthe DOM event associated with the change.
- valuethe updated value.
Type
FocusEventHandler<HTMLTextAreaElement>
Description
An Event handler function. Fires when the input element gains focus.
Type
string
Description
HTML placeholder attribute.
Type
boolean
Default
false
Description
If true, the component is not editable by the user.
Type
| 'none'| 'both'| 'horizontal'| 'vertical'| 'initial'| 'inherit'
Default
"both"
Description
HTML resize attribute.
Type
| 's'| 'm'| 'l'
Description
Size of the element, label, hint, and error messages. When these properties
are supplied as templates, size styles are omitted.
Type
CSSProperties
Description
The style global attribute
contains CSS styling
declarations to be applied to the element.
Type
T
Description
Controlled input value.
Type
| 'soft'| 'hard'
Default
"soft"
Description
HTML wrap attribute.