suiss/ui · Component
Textarea
A multi-line text field that grows with its content, with an optional resize handle.
Textarea is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Textarea renders a native textarea styled to match the other form controls. By default it uses field-sizing: content, so it grows as people type, starting at a minimum height of 4rem.
Set resizable to give it a fixed height and a custom handle that people drag to resize it vertically. Use Textarea for free-form text such as messages or notes; for a single line, use Input.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
-
Add the
cnhelper. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Examples
With value
Set defaultValue to start the field with text.
With label
Pair the textarea with a Label through htmlFor and id, and link hint text with aria-describedby.
Resizable
Set resizable="inside" to add a resize handle inside the bottom corner of the field. Double-click the handle to reset the height.
Resizable outside
Set resizable="outside" to place the handle just outside the bottom corner of the field.
Large
Set size="lg" for more padding and 17px text, to match lg inputs.
Disabled
Set disabled so the textarea can't be edited. The resize handle is hidden while it is disabled.
Invalid
Set aria-invalid to show an error state with a destructive border.
Accessibility
- Renders a native
textareawith thetextboxrole. Name it with aLabeloraria-label. - The resize handle is hidden from assistive technologies and works with a pointer only.
- An invalid field is exposed through
aria-invalid.
API Reference
Textarea
The multi-line text field, with an optional resize handle.
| Prop | Type | Default |
|---|---|---|
resizable | "inside" | "outside" | - |
size | "default" | "lg" | "default" |
Also accepts the props of React.ComponentProps<"textarea">.
Textarea passes its props to the native element, so use value with onChange to control it, or defaultValue for an uncontrolled field.
resizable adds a vertical resize handle, placed inside or outside the field's bottom corner, and turns off automatic growth. The textarea and its handle are then wrapped in a relative container. A resizable textarea starts at a minimum height of 6rem, dragging never shrinks it below its minimum height, and the handle mirrors in right-to-left layouts.
size="lg" starts at 54px with 16px side padding and 17px text. The textarea uses data-slot="textarea", sets data-size, and sets data-resizable when resizable; the wrapper and handle use textarea-container and textarea-handle.
Web preview
Textarea is the multi-line version of Input. It wraps a TextInput through the same field control primitive, defaults to multiline with numberOfLines={8}, aligns text to the top and has a minimum height. It shows a focus border while editing, a destructive border and tint when invalid, and 50% opacity when disabled.
Use it for comments, messages and other free-form text. Use Input for single-line values.
Installation
- Install the following dependencies:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/textarea.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/textarea.tsx:
- Update the import paths to match your project setup.
- Copy the primitives it uses into
components/primitives:
- Copy and paste the following code into
components/ui/textarea.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
With value
A textarea that starts with a defaultValue.
A textarea that starts with a value.
Web preview
With label
A textarea inside a Field, which gives it the field's label and description.
Web preview
Large
The lg size, with more padding and 17 point text to match lg inputs.
Web preview
Disabled
A disabled textarea that can't be edited.
Web preview
Invalid
A textarea inside an invalid Field, which gives it a destructive border and an error message.
Web preview
Accessibility
- Inside a
Field, the textarea gets the field label asaccessibilityLabeland the description asaccessibilityHint. disabledis set inaccessibilityStateand makes the textarea non-editable.- Outside a
Field, give it anaccessibilityLabel.
API Reference
Textarea
The multi-line text field.
| Prop | Type | Default |
|---|---|---|
size | "default" | "lg" | "default" |
Also accepts the props of React.ComponentProps<typeof InputPrimitive.Root>.
The value works controlled with value and onValueChange(value, details), or uncontrolled with defaultValue. Inside a Field, the textarea picks up the field's label, description, invalid and disabled state. Override numberOfLines or set a height through className to change the visible size. size="lg" starts at 54 tall with 16 point side padding and 17 point text. Focus turns the border outline to ring with a solid ring.
.textFieldStyle(.textarea)
Style that creates TextareaStyle.
| Parameter | Type | Default |
|---|---|---|
size | TextareaStyle.Size: .default | .lg | .default |
TextareaSize
Values: Default, Lg.
Textarea
The multi-line text field.
| Parameter | Type | Default |
|---|---|---|
value | String | - |
onValueChange | (String) -> Unit | - |
modifier | Modifier | Modifier |
size | TextareaSize: Default | Lg | TextareaSize.Default |
enabled | Boolean | LocalFieldState.current.enabled |
readOnly | Boolean | false |
invalid | Boolean | LocalFieldState.current.invalid |
placeholder | String? | null |
minLines | Int | 1 |
maxLines | Int | Int.MAX_VALUE |
keyboardOptions | KeyboardOptions | KeyboardOptions.Default |
keyboardActions | KeyboardActions | KeyboardActions.Default |
interactionSource | MutableInteractionSource? | null |