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
import React from 'react'; import CheckBox from 'devextreme-react/check-box'; import SelectBox from 'devextreme-react/select-box'; import TextArea from 'devextreme-react/text-area'; import service from './data.js'; const { valueChangeEvents } = service; const notesLabel = { 'aria-label': 'Notes' }; const eventLabel = { 'aria-label': 'Event' }; class App extends React.Component { constructor(props) { super(props); this.state = { value: service.getContent(), valueForEditableTestArea: service.getContent(), maxLength: null, eventValue: valueChangeEvents[0].name, autoResizeEnabled: false, height: 90, }; this.onCheckboxValueChanged = this.onCheckboxValueChanged.bind(this); this.onSelectBoxValueChanged = this.onSelectBoxValueChanged.bind(this); this.onTextAreaValueChanged = this.onTextAreaValueChanged.bind(this); this.onAutoResizeChanged = this.onAutoResizeChanged.bind(this); } render() { return ( <React.Fragment> <div className="dx-fieldset"> <div className="dx-fieldset-header">Default Mode</div> <div className="dx-field"> <CheckBox defaultValue={false} onValueChanged={this.onCheckboxValueChanged} text="Limit text length"></CheckBox> </div> <div className="dx-field"> <CheckBox value={this.state.autoResizeEnabled} onValueChanged={this.onAutoResizeChanged} text="Enable auto resize"></CheckBox> </div> </div> <div className="left-content"> <TextArea height={this.state.height} maxLength={this.state.maxLength} defaultValue={this.state.value} inputAttr={notesLabel} autoResizeEnabled={this.state.autoResizeEnabled} /> </div> <div className="full-width-content"> <div className="dx-fieldset"> <div className="dx-fieldset-header">Event Handling and API</div> <div className="dx-field"> <div className="dx-field-label">Synchronize text areas </div> <div className="dx-field-value"> <SelectBox items={valueChangeEvents} valueExpr="name" displayExpr="title" inputAttr={eventLabel} value={this.state.eventValue} onValueChanged={this.onSelectBoxValueChanged} /> </div> </div> </div> <TextArea height={90} value={this.state.valueForEditableTestArea} valueChangeEvent={this.state.eventValue} inputAttr={notesLabel} onValueChanged={this.onTextAreaValueChanged} /> <TextArea height={90} value={this.state.valueForEditableTestArea} readOnly={true} inputAttr={notesLabel} valueChangeEvent={this.state.eventValue} /> </div> </React.Fragment> ); } onCheckboxValueChanged(e) { const str = service.getContent(); this.setState({ value: e.value ? str.substring(0, 100) : str, maxLength: e.value ? 100 : null, }); } onAutoResizeChanged(e) { this.setState({ autoResizeEnabled: e.value, height: e.value ? undefined : 90, }); } onSelectBoxValueChanged(e) { this.setState({ eventValue: e.value, }); } onTextAreaValueChanged(e) { this.setState({ valueForEditableTestArea: e.value, }); } } export default App;
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render( <App />, document.getElementById('app'), );
<!DOCTYPE html> <html> <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" /> <link rel="stylesheet" type="text/css" href="" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src=""></script> <script src=""></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import("./index.js"); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"></div> </div> </body> </html>
.full-width-content { width: 100%; margin-top: 30px; } .full-width-content > .dx-widget { margin-bottom: 20px; } .full-width-content .dx-field { max-width: 385px; }
const valueChangeEvents = [{ title: 'On Change', name: 'change', }, { title: 'On Key Up', name: 'keyup', }]; const content = '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.'; export default { valueChangeEvents, getContent() { return content; }, };
window.exports = window.exports || {}; window.config = { transpiler: 'plugin-babel', meta: { 'devextreme/localization.js': { 'esModule': true, }, }, paths: { 'npm:': '', }, defaultExtension: 'js', map: { 'react': 'npm:react@17.0.2/umd/react.development.js', 'react-dom': 'npm:react-dom@17.0.2/umd/react-dom.development.js', 'prop-types': 'npm:prop-types@15.8.1/prop-types.js', 'rrule': 'npm:rrule@2.6.4/dist/es5/rrule.js', 'luxon': 'npm:luxon@1.28.1/build/global/luxon.min.js', 'es6-object-assign': 'npm:es6-object-assign@1.1.0', 'devextreme': 'npm:devextreme@23.1.6/cjs', 'devextreme-react': 'npm:devextreme-react@23.1.6', 'jszip': 'npm:jszip@3.7.1/dist/jszip.min.js', 'devextreme-quill': 'npm:devextreme-quill@1.6.2/dist/dx-quill.min.js', 'devexpress-diagram': 'npm:devexpress-diagram@2.2.2/dist/dx-diagram.js', 'devexpress-gantt': 'npm:devexpress-gantt@4.1.49/dist/dx-gantt.js', '@devextreme/runtime': 'npm:@devextreme/runtime@3.0.12', 'inferno': 'npm:inferno@7.4.11/dist/inferno.min.js', 'inferno-compat': 'npm:inferno-compat/dist/inferno-compat.min.js', 'inferno-create-element': 'npm:inferno-create-element@7.4.11/dist/inferno-create-element.min.js', 'inferno-dom': 'npm:inferno-dom/dist/inferno-dom.min.js', 'inferno-hydrate': 'npm:inferno-hydrate@7.4.11/dist/inferno-hydrate.min.js', 'inferno-clone-vnode': 'npm:inferno-clone-vnode/dist/inferno-clone-vnode.min.js', 'inferno-create-class': 'npm:inferno-create-class/dist/inferno-create-class.min.js', 'inferno-extras': 'npm:inferno-extras/dist/inferno-extras.min.js', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0.0.25/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0.0.25/systemjs-babel-browser.js', // Prettier 'prettier/standalone': 'npm:prettier@2.8.4/standalone.js', 'prettier/parser-html': 'npm:prettier@2.8.4/parser-html.js', }, packages: { 'devextreme': { defaultExtension: 'js', }, 'devextreme-react': { main: 'index.js', }, 'devextreme/events/utils': { main: 'index', }, 'devextreme/events': { main: 'index', }, 'es6-object-assign': { main: './index.js', defaultExtension: 'js', }, }, packageConfigPaths: [ 'npm:@devextreme/*/package.json', 'npm:@devextreme/runtime@3.0.12/inferno/package.json', ], babelOptions: { sourceMaps: false, stage0: true, react: true, }, }; System.config(window.config);