DevExtreme v23.2 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Text Area

The TextArea component enables users to enter and edit multi-line text. This component can have a fixed or resizable height. The component with the fixed height displays a native scroll bar if the entered text exceeds the text area. If you set the autoResizeEnabled property to true, the TextArea automatically resizes its height to fit the text.

You can also specify the maxLength property to limit the number of characters a user can enter. Note that this property only limits the number of characters for users. You can enter text that exceeds the maximum character length programmatically, but the number of characters displayed to users will still be limited by this property setting.

The TextArea stores the text in the value property and updates it after the DOM event occurs. To specify which DOM event to use instead of the default "change" event, use the valueChangeEvent property. To handle the value change, use the TextArea's onValueChanged function.

Change the text in the Event Handling and API section below to see how this feature works. Use the "Synchronize text areas" drop-down menu to select which event updates the read-only component's value: "change" or "keyup".

Backend API
$(() => { const exampleTextArea = $('#example-textarea').dxTextArea({ value: longText, height: 90, inputAttr: { 'aria-label': 'Notes' }, }).dxTextArea('instance'); $('#set-max-length').dxCheckBox({ value: false, onValueChanged(data) { const str = data.value ? exampleTextArea.option('value').substring(0, 100) : longText; exampleTextArea.option('value', str); exampleTextArea.option('maxLength', data.value ? 100 : null); }, text: 'Limit text length', }); $('#set-resize').dxCheckBox({ value: false, onValueChanged(e) { exampleTextArea.option('autoResizeEnabled', e.value); exampleTextArea.option('height', e.value ? undefined : 90); }, text: 'Enable auto resize', }); const valueChangeEvents = [{ title: 'On Change', name: 'change', }, { title: 'On Key Up', name: 'keyup', }]; $('#change-event').dxSelectBox({ items: valueChangeEvents, inputAttr: { 'aria-label': 'Event' }, value: valueChangeEvents[0].name, valueExpr: 'name', displayExpr: 'title', onValueChanged(data) { editingTextArea.option('valueChangeEvent', data.value); }, }); const editingTextArea = $('#editing-textarea').dxTextArea({ value: longText, height: 90, valueChangeEvent: 'change', inputAttr: { 'aria-label': 'Notes' }, onValueChanged(data) { disabledTextArea.option('value', data.value); }, }).dxTextArea('instance'); const disabledTextArea = $('#disabled-textarea').dxTextArea({ value: longText, height: 90, readOnly: true, inputAttr: { 'aria-label': 'Notes' }, }).dxTextArea('instance'); });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/23.2.5/css/dx.light.css" /> <script src="js/dx.all.js"></script> <script src="data.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div class="dx-fieldset"> <div class="dx-fieldset-header">Default Mode</div> <div class="dx-field"> <div id="set-max-length"></div> </div> <div class="dx-field"> <div id="set-resize"></div> </div> </div> <div class="textarea-wrapper"> <div id="example-textarea"></div> </div> <div class="full-width-content"> <div class="dx-fieldset"> <div class="dx-fieldset-header">Event Handling and API</div> <div class="dx-field"> <div class="dx-field-label">Synchronize text areas </div> <div class="dx-field-value"> <div id="change-event"></div> </div> </div> </div> <div class="textarea-wrapper"> <div id="editing-textarea"></div> <div id="disabled-textarea"></div> </div> </div> </div> </body> </html>
.full-width-content { width: 100%; margin-top: 30px; } .full-width-content .textarea-wrapper > .dx-widget { margin-bottom: 20px; } .full-width-content .dx-field { max-width: 385px; } .textarea-wrapper { padding: 0 20px; }
const longText = 'Prepare 2013 Marketing Plan: We need to double revenues in 2013 and our marketing strategy is going to be key here. R&D is improving existing products and creating new products so we can deliver great AV equipment to our customers.Robert, please make certain to create a PowerPoint presentation for the members of the executive team.';