---
title: Long Text
product: Form Library
description: Get more insights for qualitative research with the open-ended comment question type. It is essentially an open-ended question that provides more space for the respondent to write a longer or more detailed answer. This free demo for JavaScript will show you how to configure and add a comment field to your form.
framework: React
source: https://surveyjs.io/form-library/examples/add-open-ended-question-to-a-form/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Long Text (React)

A Long Text (or Comment) question is a multi-line text input field that allows users to give detailed responses and share their feelings, experiences, or opinions on a subject. Unlike single- or multi-select questions that offer predefined options, a Long Text question asks respondents to express their thoughts in their own words. This example demonstrates how to create and configure a Long text question. Switch between React, Vue, jQuery, Angular, and Vanilla JS to view the example for your JavaScript framework/library.

## Create a Long Text Question

To create a Long Text form field, define an object with the `type` property set to `"comment"` and add it to the [`elements`](https://surveyjs.io/form-library/documentation/pagemodel#elements) array. Within this object, specify the question's [`title`](https://surveyjs.io/form-library/documentation/api-reference/comment-field-model#title) and a unique [`name`](https://surveyjs.io/form-library/documentation/api-reference/comment-field-model#name) that identifies the question. Optionally, you can specify a [`description`](https://surveyjs.io/form-library/documentation/api-reference/comment-field-model#description) to appear under the `title` and a [`placeholder`](https://surveyjs.io/form-library/documentation/api-reference/comment-field-model#placeholder) to display within the comment area.

## Resize the Comment Area

The comment area of a Long Text question occupies the height of four rows of text on the screen. If you want to change this number and increase or decrease the height, set the [`rows`](https://surveyjs.io/form-library/documentation/api-reference/comment-field-model#rows) property.

When the content exceeds the comment area, a vertical scrollbar appears. Enable the [`autoGrow`](https://surveyjs.io/form-library/documentation/api-reference/comment-field-model#autoGrow) property if you want the comment area to automatically expand or shrink to accommodate the content and thus remove the scrollbar. You can also enable `SurveyModel`'s [`autoGrowComment`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#autoGrowComment) property to activate the same feature for all comment areas in a survey.

A Long Text question displays a resize handle that allows users to resize the comment area. If you want to hide the handle, disable the [`allowResize`](https://surveyjs.io/form-library/documentation/api-reference/comment-field-model#allowResize) property in an individual Long Text question's configuration or the [`allowResizeComment`](https://surveyjs.io/form-library/documentation/surveymodel#allowResizeComment) in `SurveyModel`. The latter property hides the resize handle for all comment areas.

## Limit the Number of Input Characters

A Long Text form field accepts an unlimited number of characters. If you want to set a limit, use the [`maxLength`](https://surveyjs.io/form-library/documentation/api-reference/comment-field-model#maxLength) property. With this setting, the comment area displays a character count.

## Files

### `public/index.html`

```html
<div id="surveyElement" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: 100%; height:100%"></div>
```

### `src/SurveyComponent.jsx`

```js
import React from "react";
import { Model } from "survey-core";
import { Survey } from "survey-react-ui";
import "survey-core/survey-core.min.css";
import "./index.css";
import { json } from "./json";

function SurveyComponent() {
    const survey = new Model(json);
    survey.onComplete.add((sender, options) => {
        console.log(JSON.stringify(sender.data, null, 3));
    });
    return (<Survey model={survey} />);
}

export default SurveyComponent;
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyComponent from "./SurveyComponent";

const root = createRoot(document.getElementById("surveyElement"));
root.render(<SurveyComponent />);
```

### `src/json.js`

```js
export const json = {
 "pages": [
  {
   "name": "page1",
   "elements": [
    {
      "type": "comment",
      "name": "suggestions-auto-grow",
      "title": "What would make you more satisfied with our product?",
      "description": "The comment area has an initial height of two rows and automatically expands or shrinks to accomodate the content.",
      "rows": 2,
      "autoGrow": true,
      "allowResize": false
    },
    {
      "type": "comment",
      "name": "suggestions-max-length",
      "title": "What would make you more satisfied with our product?",
      "description": "The comment area is resizable and limited to 500 characters.",
      "maxLength": 500
    }
   ]
  }
 ]
};
```

### `src/theme.js`

```js
export const themeJson = {};
```

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "survey-core": "latest",
    "survey-react-ui": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/add-open-ended-question-to-a-form/angular.md)
- [Vue 3](https://surveyjs.io/form-library/examples/add-open-ended-question-to-a-form/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/add-open-ended-question-to-a-form/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/add-open-ended-question-to-a-form/vanillajs.md)
