Create and configure Syncfusion JavaScript TextBox components. Use this skill when building text input fields, implementing floating labels, adding adornments (icons/buttons), creating multiline text areas, applying validation states, or customizing TextBox styling. Covers single-line inputs, read-only fields, disabled states, sizing variations, and accessibility features.
The TextBox is a lightweight input control that accepts text and allows customization with floating labels, adornments, validation states, and styling. This skill guides you through implementing and configuring TextBox components for various use cases.
Use this skill when you need to:
The TextBox is essential for collecting user input in modern applications. It provides:
The TextBox component is available in the @syncfusion/ej2-inputs package:
npm install @syncfusion/ej2-inputs @syncfusion/ej2-base
Import required CSS themes:
import '@syncfusion/ej2-base/styles/material.css';
import '@syncfusion/ej2-inputs/styles/material.css';
📄 Read: references/getting-started.md
placeholder, value, floatLabelType📄 Read: references/input-states.md
📄 Read: references/adornments.md
prependTemplate and appendTemplate📄 Read: references/floating-labels.md
📄 Read: references/multiline-textbox.md
multiline: truemaxLength📄 Read: references/styling-sizing.md
e-small), bigger (e-bigger)e-filled, e-outline)cssClass📄 Read: references/accessibility.md
aria-placeholder, aria-labelledbyimport { TextBox } from '@syncfusion/ej2-inputs';
// Create a simple text input
const textbox = new TextBox({
placeholder: 'Enter your name'
});
textbox.appendTo('#textbox');
import { TextBox } from '@syncfusion/ej2-inputs';
const textbox = new TextBox({
placeholder: 'Email Address',
floatLabelType: 'Auto' // Label floats on focus or when filled
});
textbox.appendTo('#email');
import { TextBox } from '@syncfusion/ej2-inputs';
const textbox = new TextBox({
placeholder: 'Search',
floatLabelType: 'Never',
created: () => {
textbox.addIcon('append', 'e-icons e-search');
}
});
textbox.appendTo('#search');
import { TextBox } from '@syncfusion/ej2-inputs';
// Error state
const errorBox = new TextBox({
placeholder: 'Username',
cssClass: 'e-error',
value: ''
});
errorBox.appendTo('#error');
// Success state
const successBox = new TextBox({
placeholder: 'Confirmed',
cssClass: 'e-success',
value: 'valid input'
});
successBox.appendTo('#success');
const emailBox = new TextBox({
placeholder: 'Email Address',
floatLabelType: 'Auto',
created: () => {
emailBox.addIcon('prepend', 'e-icons e-people');
}
});
emailBox.appendTo('#email');
When to use: Collecting email addresses in forms or contact sections.
const passwordBox = new TextBox({
placeholder: 'Password',
type: 'password',
floatLabelType: 'Auto',
created: () => {
passwordBox.addIcon('append', 'e-icons e-eye');
}
});
passwordBox.appendTo('#password');
// Toggle visibility on icon click
const eyeIcon = document.querySelector('#password .e-eye');
eyeIcon.addEventListener('click', () => {
if (passwordBox.type === 'password') {
passwordBox.type = 'text';
eyeIcon.className = 'e-icons e-eye-slash';
} else {
passwordBox.type = 'password';
eyeIcon.className = 'e-icons e-eye';
}
passwordBox.dataBind();
});
When to use: Secure password entry with visibility toggle option.
const addressBox = new TextBox({
placeholder: 'Enter your address',
floatLabelType: 'Auto',
multiline: true,
created: (args) => {
addressBox.addAttributes({ rows: '4' });
}
});
addressBox.appendTo('#address');
When to use: Collecting longer text like addresses, descriptions, or comments.
const usernameBox = new TextBox({
placeholder: 'Username (3+ characters)',
floatLabelType: 'Auto'
});
usernameBox.appendTo('#username');
usernameBox.element.addEventListener('blur', (e) => {
const value = usernameBox.value;
if (value.length < 3) {
usernameBox.cssClass = 'e-error';
} else {
usernameBox.cssClass = 'e-success';
}
usernameBox.dataBind();
});
When to use: Real-time validation feedback as users type or leave the field.
| Property | Type | Description |
|---|---|---|
placeholder | string | Hint text displayed when empty |
value | string | Current input value |
floatLabelType | 'Never' | 'Always' | 'Auto' | Label behavior (default: 'Never') |
multiline | boolean | Enable multiline mode (textarea) |
cssClass | string | Custom CSS classes (e.g., 'e-error', 'e-success', 'e-small') |
type | string | Input type ('text', 'password', 'email', etc.) |
disabled | boolean | Disable the input |
readonly | boolean | Make input read-only |
prependTemplate | string | HTML content before the input |
appendTemplate | string | HTML content after the input |
created | function | Event fired when component is created |