Textarea
A multi-line input component for capturing longer text content from users, such as comments or messages.
The Textarea
component provides a flexible and customizable input field that can handle multi-line text entries. It can be styled to fit different layouts and is perfect for situations where users need to enter longer text, such as feedback forms, comments, or code editors.
Usage
The Textarea
component is designed for handling multi-line text input. It can be used in forms, feedback sections, or anywhere where users need to provide more extensive information. Below is a basic example demonstrating how to use the Textarea
component effectively in your project.
Textarea Validate Json
If your Textarea
is intended for handling JSON input or any structured data, validation is crucial. This section demonstrates how to use the Textarea
component along with validation, ensuring that the data entered by the user is in a valid JSON format.
Tip:
Use the
resize
property to control whether the user can resize the textarea. It's great for keeping the layout consistent, especially on fixed-width containers.
Note:
Ensure that proper validation is in place when using
Textarea
for sensitive input types, like JSON or code, to provide immediate feedback for users.
API References
JsonInput is based on Textarea component, it includes json validation logic and option to format input value on blur.
Textarea will adjust its height when you give it a value that exceeds its initial height, this approach will help you more to review what you have typed previously.
Styles API
Styles API | Type | Default | Annotation |
---|---|---|---|
unstyled? | boolean | false | if true , all default styles will be removed |
Props API
Props API | Type | Default | Annotation |
---|---|---|---|
autosize? | boolean | true | determines whether the textarea height should grow with its content |
serialize? | typeof JSON.stringify | JSON.stringify | function to serialize value into a string, used for value formatting |
deserialize? | typeof JSON.parse | JSON.parse | function to deserialize string value, used for value formatting and input JSON validation, must throw error if string cannot be processed |
validateJson? | boolean | false | options for JSON validation |
formatOnBlur? | boolean | false | options for formatting JSON when blurring |
validationError? | string | "Invalid JSON" | message thrown if JSON invalid |
onValidationError? | (error: Error | null) => void | undefined | callback when validation fails |
Source Codes
Full working code example, including necessary markup and styles. You can copy and paste this code directly to start using the component immediately.