- Filled and outline mode
- Custom styling with cssClass API in TextArea
- Setting the disabled state in TextArea
- Set the readonly TextArea
- Set the rounded corner in TextArea
- Static clear button in TextArea
- Customize the TextArea background color and text color
- Change the floating label color of the TextArea
- Adding mandatory asterisk to placeholder
Contact Support
Sizing in Angular TextArea Component
13 Jun 202417 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 { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextAreaModule} from '@syncfusion/ej2-angular-inputs'
import { Component } from '@angular/core';
@Component({
imports: [
TextAreaModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<div class='textarea'>
<h4> Small Size </h4>
<div className="e-input-group e-small">
<ejs-textarea id="default1" className="e-input" placeholder="Enter your comments" (focus)= "onfocus($event)" (blur)="onBlur($event)"></ejs-textarea>
</div>
<h4> Bigger Size </h4>
<div className="e-input-group e-bigger">
<ejs-textarea id="default2" className="e-input" placeholder="Enter your comments" (focus)= "onfocus($event)" (blur)="onBlur($event)"></ejs-textarea>
</div>
</div>
</div>`
})
export class AppComponent {
public onfocus(args: any): void {
args.target.parentElement.classList.add("e-input-focus");
}
public onBlur(args: any): void {
args.target.parentElement.classList.remove("e-input-focus");
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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 { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextAreaModule} from '@syncfusion/ej2-angular-inputs'
import { Component } from '@angular/core';
@Component({
imports: [
TextAreaModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<div class='textarea'>
<label className="custom-input-label"> Filled TextArea </label>
<div id='container'>
<ejs-textarea id='filled' placeholder="Filled" floatLabelType="Auto" cssClass="e-filled"></ejs-textarea>
</div>
<label className="custom-input-label"> Outlined TextArea </label>
<div id='container1'>
<ejs-textarea id='outlined' placeholder="Outlined" floatLabelType="Auto" cssClass="e-outline"></ejs-textarea>
</div>
</div>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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 { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextAreaModule} from '@syncfusion/ej2-angular-inputs'
import { Component } from '@angular/core';
@Component({
imports: [
TextAreaModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<div class='textarea'>
<ejs-textarea id='default' placeholder="Enter your comments" floatLabelType="Auto" cssClass="custom-textarea"></ejs-textarea>
</div>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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 { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `<!-- To Render TextArea component. -->
<div class="wrap">
<ejs-textarea id='default' enabled="false"></ejs-textarea>
</div>`
})
export class AppComponent { }
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 { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `<!-- To Render TextArea component. -->
<div class="wrap">
<ejs-textarea id='default' readonly="true" value="Readonly"></ejs-textarea>
</div>`
})
export class AppComponent { }
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 { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `<!-- To Render TextArea component. -->
<div class="wrap">
<div class="e-input-group e-corner">
<textarea class="e-input" placeholder="Enter your comments"></textarea>
</div>
</div>`
})
export class AppComponent { }
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 { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextAreaModule} from '@syncfusion/ej2-angular-inputs'
import { Component } from '@angular/core';
@Component({
imports: [
TextAreaModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<div class='textarea'>
<ejs-textarea id='default' placeholder="Enter your comments" cssClass="e-static-clear" showClearButton="true"></ejs-textarea>
</div>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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 { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextAreaModule} from '@syncfusion/ej2-angular-inputs'
import { Component } from '@angular/core';
@Component({
imports: [
TextAreaModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<div class='textarea'>
<ejs-textarea id='default' placeholder="Enter your comments" floatLabelType="Auto"></ejs-textarea>
</div>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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 { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextAreaModule} from '@syncfusion/ej2-angular-inputs'
import { Component } from '@angular/core';
@Component({
imports: [
TextAreaModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<div class='textarea'>
<div>
<ejs-textarea id='default1' placeholder="Success" floatLabelType="Auto" cssClass="e-success"></ejs-textarea>
</div>
<div>
<ejs-textarea id='default2' placeholder="Warning" floatLabelType="Auto" cssClass="e-warning"></ejs-textarea>
</div>
</div>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
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 { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextAreaModule} from '@syncfusion/ej2-angular-inputs'
import { Component } from '@angular/core';
@Component({
imports: [
TextAreaModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<div class='textarea'>
<ejs-textarea id='default' placeholder="Enter your comments" floatLabelType="Auto"></ejs-textarea>
</div>
</div>`
})
export class AppComponent { }
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));