Sizing in React TextArea Component

25 Mar 202421 minutes to read

you can adjust the size of the TextArea by applying specific classes:

Property Description
Small Add the e-small class to the input element or its container to render a smaller-sized TextArea.
Bigger Add the e-bigger class to the input element or its container to render a larger-sized TextArea.

By applying these classes, users can easily customize the appearance of the TextArea to better fit their application’s design requirements.

import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    return (
        <div className='wrap'>
            <h4> Small Size </h4>

            <div className="e-input-group e-small">
                <textarea className="e-input" placeholder="Enter your comments" onFocus={floatFocus} onBlur={floatBlur}></textarea>
            </div>

            <h4> Bigger Size </h4>

            <div className="e-input-group e-bigger">
                <textarea className="e-input" placeholder="Enter your comments" onFocus={floatFocus} onBlur={floatBlur}></textarea>
            </div>
        </div>
    );
}

function floatFocus(args) {
    args.target.parentElement.classList.add("e-input-focus");
}

function floatBlur(args) {
    args.target.parentElement.classList.remove('e-input-focus');
}

export default App;
ReactDom.render(<App />, document.getElementById('input-container'));
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    
    return (
        <div className='wrap'>
            <h4> Small Size </h4>

            <div className="e-input-group e-small">
                <textarea className="e-input" placeholder="Enter your comments" onFocus={floatFocus} onBlur={floatBlur}></textarea>
            </div>

            <h4> Bigger Size </h4>

            <div className="e-input-group e-bigger">
                <textarea className="e-input" placeholder="Enter your comments" onFocus={floatFocus} onBlur={floatBlur}></textarea>
            </div>
        </div>
    );
}

function floatFocus(args: React.FocusEvent) {
    args.target.parentElement.classList.add("e-input-focus");
}

function floatBlur(args: React.FocusEvent) {
    args.target.parentElement.classList.remove('e-input-focus');
}

export default App;
ReactDom.render(<App />,document.getElementById('input-container'));

Filled and outline mode

The Filled and Outline modes can be enabled in the TextArea component by adding the e-outline or e-filled class to the cssClass API.
By adding these classes, users can choose between a filled or outline appearance for the TextArea component, aligning with the design aesthetics of their application.

// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    return (
        <div className='wrap'>
            <label className="custom-input-label"> Filled TextArea </label>
            <div id='container'>
                <TextAreaComponent id='filled' placeholder="Filled" floatLabelType="Auto" cssClass="e-filled"></TextAreaComponent>
            </div>
            <label className="custom-input-label"> Outlined TextArea </label>
            <div id='container1'>
                <TextAreaComponent id='outlined' placeholder="Outlined" floatLabelType="Auto" cssClass="e-outline"></TextAreaComponent>
            </div>
        </div>
    );
}

export default App;
ReactDom.render(<App />, document.getElementById('input-container'));
// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    
    return (
        <div className='wrap'>
            <label className="custom-input-label"> Filled TextArea </label>
            <div id='container'>
                <TextAreaComponent id='filled' placeholder="Filled" floatLabelType="Auto" cssClass="e-filled"></TextAreaComponent>
            </div>
            <label className="custom-input-label"> Outlined TextArea </label>
            <div id='container1'>
                <TextAreaComponent id='outlined' placeholder="Outlined" floatLabelType="Auto" cssClass="e-outline"></TextAreaComponent>
            </div>
        </div>
    );
}

export default App;
ReactDom.render(<App />,document.getElementById('input-container'));

Note: Filled and Outline theme customization are available only with Material themes.

Custom styling with cssClass API in TextArea

The cssClass Api provides a powerful way to apply custom styling to the TextArea component, allowing users to customize its appearance and layout according to their design requirements.

By utilizing the cssClass API, users can apply custom CSS classes to the TextArea component’s container, enabling control over its styling properties such as color, padding, margins, borders, and more.

// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    return (
        <div className='wrap'>
            <TextAreaComponent id='default' placeholder="Enter your comments" floatLabelType="Auto" cssClass="custom-textarea"></TextAreaComponent>
        </div>
    );
}

export default App;
ReactDom.render(<App />, document.getElementById('input-container'));
// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    
    return (
        <div className='wrap'>
            <TextAreaComponent id='default' placeholder="Enter your comments" floatLabelType="Auto" cssClass="custom-textarea"></TextAreaComponent>
        </div>
    );
}

export default App;
ReactDom.render(<App />,document.getElementById('input-container'));

Setting the disabled state in TextArea

To disable the TextArea, you can utilize the enabled property. When set to false, the TextArea becomes disabled, preventing user interaction.

{/* Import the TextArea. */}
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

{/* To render TextArea.*/}
function App() {
  
    return (
        <div className='wrap'>
            <TextAreaComponent id="default" enabled={false}></TextAreaComponent>
        </div>
    );
}
export default App;
ReactDom.render(<App />,document.getElementById('input-container'));

Set the readonly TextArea

To make the TextArea read-only , you can use the readonly property. When set to true, it prevents users from editing the content of the TextArea.

{/* Import the TextArea. */}
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

{/* To render TextArea.*/}
function App() {
  
    return (
        <div className='wrap'>
            <TextAreaComponent id="default" readonly={true}></TextAreaComponent>
        </div>
    );
}
export default App;
ReactDom.render(<App />,document.getElementById('input-container'));

Set the rounded corner in TextArea

Render the TextArea with rounded corner by adding the e-corner class to the input parent element.

This rounded corner is visible only in box model input component

import * as React from 'react';
import * as ReactDom from 'react-dom';

{/* To render TextArea.*/}
function App() {
  
    return (
        <div class="e-input-group e-corner">
            <textarea class="e-input" placeholder="Enter your comments"></textarea>
        </div>
    );
}
export default App;
ReactDom.render(<App />,document.getElementById('input-container'));

Static clear button in TextArea

To display a static clear button in the TextArea component, you can add the e-static-clear class to the cssClass property. This class ensures that the clear button remains visible at all times, providing users with the ability to easily clear the TextArea content without needing to focus on the control.

// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    return (
        <div className='wrap'>
            <TextAreaComponent id='default' placeholder="Enter your comments" cssClass="e-static-clear" showClearButton={true}></TextAreaComponent>
        </div>
    );
}

export default App;
ReactDom.render(<App />, document.getElementById('input-container'));
// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    
    return (
        <div className='wrap'>
            <TextAreaComponent id='default' placeholder="Enter your comments" cssClass="e-static-clear" showClearButton={true}></TextAreaComponent>
        </div>
    );
}

export default App;
ReactDom.render(<App />,document.getElementById('input-container'));

Customize the TextArea background color and text color

You can customize the TextArea styles such as background-color, text-color and border-color by overriding its default styles to achieve the desired appearance for the TextArea.

// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    return (
        <div className='wrap'>
            <TextAreaComponent id='default' placeholder="Enter your comments" floatLabelType="Auto"></TextAreaComponent>
        </div>
    );
}

export default App;
ReactDom.render(<App />, document.getElementById('input-container'));
// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    
    return (
        <div className='wrap'>
            <TextAreaComponent id='default' placeholder="Enter your comments" floatLabelType="Auto"></TextAreaComponent>
        </div>
    );
}

export default App;
ReactDom.render(<App />,document.getElementById('input-container'));

Change the floating label color of the TextArea

You can change the floating label color of the TextArea for both success and warning validation states by applying the following CSS styles.

    /* For Success state */
    .e-float-input.e-success label.e-float-text,
    .e-float-input.e-success input:focus ~ label.e-float-text,
    .e-float-input.e-success input:valid ~ label.e-float-text {
      color: #22b24b;
    }

    /* For Warning state */
    .e-float-input.e-warning label.e-float-text,
    .e-float-input.e-warning input:focus ~ label.e-float-text,
    .e-float-input.e-warning input:valid ~ label.e-float-text {
      color: #ffca1c;
    }
// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    return (
        <div className='wrap'>
            <div>
                <TextAreaComponent id='default1' placeholder="Success" floatLabelType="Auto" cssClass="e-success"></TextAreaComponent>
            </div>
            <div>
                <TextAreaComponent id='default2' placeholder="Warning" floatLabelType="Auto" cssClass="e-warning"></TextAreaComponent>
            </div>
        </div>
    );
}

export default App;
ReactDom.render(<App />, document.getElementById('input-container'));
// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    
    return (
        <div className='wrap'>
            <div>
                <TextAreaComponent id='default1' placeholder="Success" floatLabelType="Auto" cssClass="e-success"></TextAreaComponent>
            </div>
            <div>
                <TextAreaComponent id='default2' placeholder="Warning" floatLabelType="Auto" cssClass="e-warning"></TextAreaComponent>
            </div>
        </div>
    );
}

export default App;
ReactDom.render(<App />,document.getElementById('input-container'));

Adding mandatory asterisk to placeholder

To add a mandatory asterisk (*) to the placeholder in the TextArea component, you can utilize CSS to append the asterisk after the placeholder text.

/* To add asterick to float label in textarea */ 
.e-float-input.e-control-wrapper .e-float-text::after {
  content: '*'; /* Add asterisk after the placeholder */
  color: red; /* Customize asterisk color */
}
// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    return (
        <div className='wrap'>
            <TextAreaComponent id='default' placeholder="Enter your comments" floatLabelType="Auto"></TextAreaComponent>
        </div>
    );
}

export default App;
ReactDom.render(<App />, document.getElementById('input-container'));
// Import the TextArea.
import { TextAreaComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';

// To render TextArea.
function App() {
    
    return (
        <div className='wrap'>
            <TextAreaComponent id='default' placeholder="Enter your comments" floatLabelType="Auto"></TextAreaComponent>
        </div>
    );
}

export default App;
ReactDom.render(<App />,document.getElementById('input-container'));