Logo

TextArea

TextArea provides a multiline text input area.
It is often used in forms, see this guide for details.

Properties

autoFocus (default: false)

If this property is set to true, the component gets the focus automatically when displayed.

autoSize (default: false)

If set to true, this boolean property enables the TextArea to resize automatically based on the number of lines inside it.
Note: If either autoSize, maxRows or minRows is set, the rows prop has no effect.
Write multiple lines in the TextArea in the demo below to see how it resizes automatically.
<App>
  <TextArea autoSize="true" />
</App>
Example: autoSize
<App>
  <TextArea autoSize="true" />
</App>

enabled (default: true)

This boolean property value indicates whether the component responds to user events (true) or not (false).
<App>
  <TextArea enabled="false" />
</App>
Example: enabled
<App>
  <TextArea enabled="false" />
</App>

enterSubmits (default: true)

This optional boolean property indicates whether pressing the Enter key on the keyboard prompts the parent Form component to submit.
Press Enter after writing something in the TextArea in the demo below. See Using Forms for details.
<App>
  <Form onSubmit="toast.success(JSON.stringify(address.value))">
    <TextArea
      id="address"
      enterSubmits="true"
      initialValue="Suzy Queue, 4455 Landing Lange, APT 4, Louisville, KY 40018-1234" />
  </Form>
</App>
Example: enterSubmits
<App>
  <Form onSubmit="toast.success(JSON.stringify(address.value))">
    <TextArea
      id="address"
      enterSubmits="true"
      initialValue="Suzy Queue, 4455 Landing Lange, APT 4, Louisville, KY 40018-1234" />
  </Form>
</App>

escResets (default: false)

This boolean property indicates whether the TextArea contents should be reset when pressing the ESC key.

initialValue

This property sets the component's initial value.
The initial value displayed in the input field.
<App>
  <TextArea initialValue="Example text" />
</App>
Example: initialValue
<App>
  <TextArea initialValue="Example text" />
</App>

label

This property sets the label of the component. If not set, the component will not display a label.

labelBreak (default: true)

This boolean value indicates whether the TextArea label can be split into multiple lines if it would overflow the available label width.

labelPosition (default: "top")

Places the label at the given position of the component.
Available values:
ValueDescription
startThe left side of the input (left-to-right) or the right side of the input (right-to-left)
endThe right side of the input (left-to-right) or the left side of the input (right-to-left)
topThe top of the input (default)
bottomThe bottom of the input

labelWidth

This property sets the width of the TextArea component's label. If not defined, the label's width will be determined by its content and the available space.

maxLength

This property sets the maximum length of the input it accepts.

maxRows

This optional property sets the maximum number of text rows the TextArea can grow. If not set, the number of rows is unlimited.
Note: If either autoSize, maxRows or minRows is set, the rows prop has no effect.
<App>
  <TextArea
    maxRows="3"
    initialValue="Lorem ipsum dolor sit amet,
    consectetur adipiscing elit,
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." />
</App>
Example: maxRows
<App>
  <TextArea
    maxRows="3"
    initialValue="Lorem ipsum dolor sit amet,
    consectetur adipiscing elit,
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." />
</App>

minRows

This optional property sets the minimum number of text rows the TextArea can shrink. If not set, the minimum number of rows is 1.
Note: If either autoSize, maxRows or minRows is set, the rows prop has no effect.
<App>
  <TextArea minRows="3" initialValue="Lorem ipsum dolor sit amet..." />
</App>
Example: minRows
<App>
  <TextArea minRows="3" initialValue="Lorem ipsum dolor sit amet..." />
</App>

placeholder

An optional placeholder text that is visible in the input field when its empty.
<App>
  <TextArea placeholder="This is a placeholder" />
</App>
Example: placeholder
<App>
  <TextArea placeholder="This is a placeholder" />
</App>

readOnly (default: false)

Set this property to true to disallow changing the component value.
<App>
  <TextArea initialValue="Example text" readOnly="{true}" />
</App>
Example: readOnly
<App>
  <TextArea initialValue="Example text" readOnly="{true}" />
</App>

required (default: false)

Set this property to true to indicate it must have a value before submitting the containing form.

resize

This optional property specifies in which dimensions can the TextArea be resized by the user.
Available values:
ValueDescription
(undefined)No resizing
horizontalCan only resize horizontally
verticalCan only resize vertically
bothCan resize in both dimensions
If you allow resizing, the TextArea turns off automatic sizing.
When you allow vertical resizing, you can limit the sizable range according to minRows and maxRows.
Drag the small resize indicators at the bottom right on each of the controls in the demo.
<App>
  <TextArea resize="vertical" minRows="1" maxRows="8" />
  <TextArea resize="both" />
</App>
Example: resize
<App>
  <TextArea resize="vertical" minRows="1" maxRows="8" />
  <TextArea resize="both" />
</App>

rows (default: 2)

Specifies the number of rows the component initially has.
Note: If either autoSize, maxRows or minRows is set, the rows prop has no effect.
<App>
  <TextArea rows="10" />
</App>
Example: rows
<App>
  <TextArea rows="10" />
</App>

validationStatus (default: "none")

This property allows you to set the validation status of the input component.
Available values:
ValueDescription
validVisual indicator for an input that is accepted
warningVisual indicator for an input that produced a warning
errorVisual indicator for an input that produced an error
This prop is used to visually indicate status changes reacting to form field validation.
<App>
  <TextArea />
  <TextArea validationStatus="valid" />
  <TextArea validationStatus="warning" />
  <TextArea validationStatus="error" />
</App>
Example: validationStatus
<App>
  <TextArea />
  <TextArea validationStatus="valid" />
  <TextArea validationStatus="warning" />
  <TextArea validationStatus="error" />
</App>

Events

didChange

This event is triggered when value of TextArea has changed.
Write in the input field and see how the Text underneath it is updated in parallel.
<App var.field="">
  <TextArea 
    initialValue="{field}" 
    onDidChange="(val) => field = val" 
  />
  <Text value="{field}" />
</App>
Example: didChange
<App var.field="">
  <TextArea 
    initialValue="{field}" 
    onDidChange="(val) => field = val" 
  />
  <Text value="{field}" />
</App>

gotFocus

This event is triggered when the TextArea has received the focus.
Clicking on the TextArea in the example demo changes the label text. Note how clicking elsewhere resets the text to the original.
<App>
  <TextArea
    initialValue="{focused === true ? 'I got focused!' : 'I lost focus...'}"
    onGotFocus="focused = true"
    onLostFocus="focused = false"
    var.focused="{false}" />
</App>
Example: gotFocus/lostFocus
<App>
  <TextArea
    initialValue="{focused === true ? 'I got focused!' : 'I lost focus...'}"
    onGotFocus="focused = true"
    onLostFocus="focused = false"
    var.focused="{false}" />
</App>

lostFocus

This event is triggered when the TextArea has lost the focus.

Exposed Methods

focus

This method sets the focus on the TextArea component.
Signature: focus(): void
<App>
  <Button label="Trigger Focus" onClick="inputComponent.focus()" />
  <TextArea id="inputComponent" />
</App>
Example: focus
<App>
  <Button label="Trigger Focus" onClick="inputComponent.focus()" />
  <TextArea id="inputComponent" />
</App>

setValue

You can use this method to set the component's current value programmatically (true: checked, false: unchecked).
<App var.changes="">
  <TextArea
    id="inputField"
    readOnly="true"
    onDidChange="changes++" />
  <HStack>
    <Button
      label="Check"
      onClick="inputField.setValue('example ')" />
    <Text value="Number of changes: {changes}" />
  </HStack>
</App>
Example: setValue
<App var.changes="">
  <TextArea
    id="inputField"
    readOnly="true"
    onDidChange="changes++" />
  <HStack>
    <Button
      label="Check"
      onClick="inputField.setValue('example ')" />
    <Text value="Number of changes: {changes}" />
  </HStack>
</App>

value

You can query the component's value. If no value is set, it will retrieve undefined.
Signature: get value(): string | undefined
In the example below, typing in the TextArea will also display the length of the text typed into it above the field:
<App>
  <Text value="TextArea content length: {inputComponent.value.length}" />
  <TextArea id="inputComponent" />
</App>
Example: value
<App>
  <Text value="TextArea content length: {inputComponent.value.length}" />
  <TextArea id="inputComponent" />
</App>

Parts

The component has some parts that can be styled through layout properties and theme variables separately:
  • endAdornment: The adornment displayed at the end of the text area.
  • input: The text area input.
  • label: The label displayed for the text area.
  • startAdornment: The adornment displayed at the start of the text area.

Styling

Theme Variables

VariableDefault Value (Light)Default Value (Dark)
backgroundColor-TextArea--disablednonenone
backgroundColor-TextArea-defaultnonenone
backgroundColor-TextArea-default--focusnonenone
backgroundColor-TextArea-default--hovernonenone
backgroundColor-TextArea-errornonenone
backgroundColor-TextArea-error--focusnonenone
backgroundColor-TextArea-error--hovernonenone
backgroundColor-TextArea-successnonenone
backgroundColor-TextArea-success--focusnonenone
backgroundColor-TextArea-success--hovernonenone
backgroundColor-TextArea-warningnonenone
backgroundColor-TextArea-warning--focusnonenone
backgroundColor-TextArea-warning--hovernonenone
borderColor-TextArea--disablednonenone
borderColor-TextArea-defaultnonenone
borderColor-TextArea-default--focusnonenone
borderColor-TextArea-default--hovernonenone
borderColor-TextArea-errornonenone
borderColor-TextArea-error--focusnonenone
borderColor-TextArea-error--hovernonenone
borderColor-TextArea-successnonenone
borderColor-TextArea-success--focusnonenone
borderColor-TextArea-success--hovernonenone
borderColor-TextArea-warningnonenone
borderColor-TextArea-warning--focusnonenone
borderColor-TextArea-warning--hovernonenone
borderRadius-TextArea-defaultnonenone
borderRadius-TextArea-errornonenone
borderRadius-TextArea-successnonenone
borderRadius-TextArea-warningnonenone
borderStyle-TextArea-defaultnonenone
borderStyle-TextArea-errornonenone
borderStyle-TextArea-successnonenone
borderStyle-TextArea-warningnonenone
borderWidth-TextArea-defaultnonenone
borderWidth-TextArea-errornonenone
borderWidth-TextArea-successnonenone
borderWidth-TextArea-warningnonenone
boxShadow-TextArea-defaultnonenone
boxShadow-TextArea-default--focusnonenone
boxShadow-TextArea-default--hovernonenone
boxShadow-TextArea-errornonenone
boxShadow-TextArea-error--focusnonenone
boxShadow-TextArea-error--hovernonenone
boxShadow-TextArea-successnonenone
boxShadow-TextArea-success--focusnonenone
boxShadow-TextArea-success--hovernonenone
boxShadow-TextArea-warningnonenone
boxShadow-TextArea-warning--focusnonenone
boxShadow-TextArea-warning--hovernonenone
fontSize-placeholder-TextArea-defaultnonenone
fontSize-placeholder-TextArea-errornonenone
fontSize-placeholder-TextArea-successnonenone
fontSize-placeholder-TextArea-warningnonenone
fontSize-TextArea-defaultnonenone
fontSize-TextArea-errornonenone
fontSize-TextArea-successnonenone
fontSize-TextArea-warningnonenone
outlineColor-TextArea-default--focusnonenone
outlineColor-TextArea-error--focusnonenone
outlineColor-TextArea-success--focusnonenone
outlineColor-TextArea-warning--focusnonenone
outlineOffset-TextArea-default--focusnonenone
outlineOffset-TextArea-error--focusnonenone
outlineOffset-TextArea-success--focusnonenone
outlineOffset-TextArea-warning--focusnonenone
outlineStyle-TextArea-default--focusnonenone
outlineStyle-TextArea-error--focusnonenone
outlineStyle-TextArea-success--focusnonenone
outlineStyle-TextArea-warning--focusnonenone
outlineWidth-TextArea-default--focusnonenone
outlineWidth-TextArea-error--focusnonenone
outlineWidth-TextArea-success--focusnonenone
outlineWidth-TextArea-warning--focusnonenone
padding-TextAreanonenone
paddingBottom-TextAreanonenone
paddingHorizontal-TextArea$space-2$space-2
paddingLeft-TextAreanonenone
paddingRight-TextAreanonenone
paddingTop-TextAreanonenone
paddingVertical-TextArea$space-2$space-2
textColor-placeholder-TextArea-defaultnonenone
textColor-placeholder-TextArea-errornonenone
textColor-placeholder-TextArea-successnonenone
textColor-placeholder-TextArea-warningnonenone
textColor-TextArea--disablednonenone
textColor-TextArea-defaultnonenone
textColor-TextArea-default--focusnonenone
textColor-TextArea-default--hovernonenone
textColor-TextArea-errornonenone
textColor-TextArea-error--focusnonenone
textColor-TextArea-error--hovernonenone
textColor-TextArea-successnonenone
textColor-TextArea-success--focusnonenone
textColor-TextArea-success--hovernonenone
textColor-TextArea-warningnonenone
textColor-TextArea-warning--focusnonenone
textColor-TextArea-warning--hovernonenone
This site is an XMLUI™ app.