Groups in React Textbox

Published on : August 03,2022
Groups in React Textbox

The following section explains you the steps required to create Text Box with icon and floating label.

Textbox :

  • Create a parent div element with the class e-input-group
  • Place input element with the class e-input inside the parent div element.

import * as React from "react";
import './App.css';
export default class App extends React.Component<{}, {}> {
public render() {
  return (
    // element which is going to render the TextBox
    <input className="e-input" type="text" placeholder="Enter Name" />
  );
}
};

 

Floating label :

  • Add the e-float-input class to the parent div element.
  • Remove the e-input class and add required attribute to the input element.
  • Place the span element with class e-float-line after the input element.
  • Place the label element with class e-float-text after the above created span element. When you focus or filled with value in the Text Box, the label floats above the Text Box.

 


import * as React from "react";
import './App.css';
export default class App extends React.Component<{}, {}> {
public render() {
  return (
    // element which is going to render the Floating TextBox
    <div className="e-float-input e-input-group">
        <input type="text" required={true}/>
        <span className="e-float-line"/>
        <label className="e-float-text">Enter Name </label>
    </div>
  );
}
};

And refer to the following sections to add the icons to the Textbox.

 

With icon and floating label

Create an icon element as a span with the class e-input-group-icon, and the user can place the icon in either side of Textbox by adding the created icon element before/after the input.

For the floating label enabled Textbox add the icon element as first or last element inside the Textbox wrapper, and based on the element position it will act as prefix or suffix icon.

 


import * as React from "react";
import * as ReactDOM from "react-dom";

export default class Default extends React.Component {

public render() {
   return (
<div>

<h4> TextBox with icons </h4>

<div className="e-input-group ">
    <input className="e-input" type="text" onFocus = {this.onInputFocus} onBlur = {this.onInputBlur} placeholder="Enter Date"/>
    <span className="e-input-group-icon e-input-popup-date" onMouseDown = {this.onIconMouseDown} onMouseUp = {this.onIconMouseUp}/>
</div>

<div className="e-input-group e-float-icon-left">
    <span className="e-input-group-icon e-input-date" onMouseDown = {this.onIconMouseDown} onMouseUp = {this.onIconMouseUp}/>
    <div className="e-input-in-wrap">
        <input className="e-input" type="text" onFocus = {this.onInputFocus} onBlur = {this.onInputBlur} placeholder="Enter Date"/>
    </div>
</div>

<div className="e-input-group e-float-icon-left">
    <span className="e-input-group-icon e-input-date" onMouseDown = {this.onIconMouseDown} onMouseUp = {this.onIconMouseUp}/>
    <div className="e-input-in-wrap">
        <input className="e-input" type="text" onFocus = {this.onInputFocus} onBlur = {this.onInputBlur} placeholder="Enter Date"/>
        <span className="e-input-group-icon e-input-down"/>
    </div>
</div>

<h4> Floating label with icons </h4>

<div className="e-float-input e-input-group">
    <input required = {true} type="text" onFocus = {this.onInputFocus} onBlur = {this.onInputBlur} />
    <span className="e-float-line"/>
    <label className="e-float-text"> Enter Date </label>
    <span className="e-input-group-icon e-input-popup-date" onMouseDown = {this.onIconMouseDown} onMouseUp = {this.onIconMouseUp}/>
</div>

<div className="e-float-input e-input-group e-float-icon-left">
    <span className="e-input-group-icon e-input-date" onMouseDown = {this.onIconMouseDown} onMouseUp = {this.onIconMouseUp}/>
    <div className="e-input-in-wrap">
        <input required = {true} type="text" onFocus = {this.onInputFocus} onBlur = {this.onInputBlur} />
        <span className="e-float-line"/>
        <label className="e-float-text"> Enter Date </label>
    </div>
</div>

<div className="e-float-input e-input-group e-float-icon-left">
    <span className="e-input-group-icon e-input-date" onMouseDown = {this.onIconMouseDown} onMouseUp = {this.onIconMouseUp}/>
    <div className="e-input-in-wrap">
        <input required = {true} type="text" onFocus = {this.onInputFocus} onBlur = {this.onInputBlur} />
        <span className="e-float-line"/>
        <label className="e-float-text"> Enter Date </label>
        <span className="e-input-group-icon e-input-down"/>
    </div>
</div>
</div>
);
}


public onInputFocus(args: React.FocusEvent) {
if (!((args.target as HTMLElement).parentElement as HTMLElement).classList.contains('e-input-in-wrap')) {
    ((args.target as HTMLElement).parentElement as HTMLElement).classList.add('e-input-focus');
} else {
    (((args.target as HTMLElement).parentElement as HTMLElement).parentElement as HTMLElement).classList.add('e-input-focus')
}
}

public onInputBlur(args: React.FocusEvent) {
if (!((args.target as HTMLElement).parentElement as HTMLElement).classList.contains('e-input-in-wrap')) {
   ((args.target as HTMLElement).parentElement as HTMLElement).classList.remove('e-input-focus');
} else {
    (((args.target as HTMLElement).parentElement as HTMLElement).parentElement as HTMLElement).classList.remove('e-input-focus');
}
}


public onIconMouseDown(args: React.MouseEvent) {
args.persist();
setTimeout(
    () => {
        (args.target as HTMLElement).classList.add('e-input-btn-ripple');
    },
300);
}

public onIconMouseUp(args: React.MouseEvent) {
(args.target as HTMLElement).classList.remove('e-input-btn-ripple');
}
}

ReactDOM.render(<Default />, document.getElementById('input-container'));

CSS :


#loader {
  color: #008cff;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;
}
#input-container {
  width: 240px;
  margin: 0 auto;
  padding: 20px 0px;
}

.e-input-group-icon {
  font-family: 'e-icons';
}

.e-input-group-icon.e-input-popup-date:before {
  content: "e901";
}

.e-input-group-icon.e-input-down:before { 
  content: "e83d";
}

.e-input-group-icon.e-input-date:before { 
  content: "e901";
}

#input-container .e-input-group { 
  margin: 26px 0;
}

#input-container .e-float-input { 
  margin: 26px 0;
}

.wrap label { 
font-weight:bold;
}

 

With clear button and floating label

The clear button is added to the input for clearing the value given in the TextBox. It is shown only when the input field has a value, otherwise not shown.

You can add the clear button to the Textbox by using showClearButton API in textbox.

import { TextBoxComponent } from '@syncfusion/ej2-react-inputs';
import * as React from "react";
import * as ReactDOM from "react-dom";
export default class App extends React.Component<{}, {}> {
public render() {
    return (
          <div className="App">
            <div className="textboxes">
                <h4>Textbox with clear button</h4>
                <TextBoxComponent placeholder="First Name" showClearButton= {true} floatLabelType="Never"/>
            </div>
            <div className="textboxes">
                <h4>Floating textbox with clear button</h4>
                <TextBoxComponent placeholder="Last Name" showClearButton= {true} floatLabelType="Auto"/>
            </div>
        </div>
    )
}
};

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

 

Floating Label without required attribute

You can render the Floating label TextBox without required attribute by manually float the label above of the Textbox using input events. You can manually float the label above of the Textbox by adding the below list of classes to the floating label element. The classes are:

Class Name Description
e-label-top Floats the label above of the TextBox.
e-label-bottom Label to be placed as placeholder for the TextBox.

 


import * as React from "react";
import * as ReactDOM from "react-dom";

export default class App extends React.Component<{}, {}> {
public textboxInstance: any;
constructor(props: any) {
    super(props);
    this.onFocusOut = this.onFocusOut.bind(this);
    this.onFocusIn = this.onFocusIn.bind(this);
    this.onInputEvt = this.onInputEvt.bind(this);
}

public onFocusOut(args: React.FocusEvent) {
    /* Update the label position based on Input value */
    this.updateLabelState((args.target as HTMLInputElement).value, ((args.target as HTMLElement).parentElement as HTMLElement).querySelector('.e-float-text') as HTMLElement);
}

public onFocusIn(args: React.FocusEvent) {
    const label = ((args.target as HTMLElement).parentElement as HTMLElement).querySelector('.e-float-text') as HTMLElement;
    label.classList.add('e-label-bottom');
    label.classList.remove('e-label-top');
}
public onInputEvt(args: React.FormEvent) {
/* Update the label position based on Input value */
  this.updateLabelState((args.target as HTMLInputElement).value, ((args.target as HTMLElement).parentElement as HTMLElement).querySelector('.e-float-text') as HTMLElement);
}

/* Update the label position based on Input value */
public updateLabelState(value: string ,label: HTMLElement) {

/* e-label-top - Float the label above of the Input */
/* e-label-bottom - Move the label to the Input */

    if (value) {
        label.classList.add('e-label-top');
        label.classList.remove('e-label-bottom');
    } else {
        label.classList.add('e-label-bottom');
        label.classList.remove('e-label-top');
    }
}

public render() {
    return (
        <div className="inner-container">
            <h4> Floating label without required attribute </h4>
            <div className="e-float-input">
              <input id='inpt1' type="text" onInput= {this.onInputEvt}  onFocus={this.onFocusIn} onBlur={ this.onFocusOut } ref = {e => this.textboxInstance = e!} />
              <span className="e-float-line"/>
              <label className="e-float-text">First Name</label>
            </div>
        </div>
    )
}

public componentDidMount() {
    /* Update the label position based on initial input value */
    this.updateLabelState(this.textboxInstance.value, this.textboxInstance.parentElement.querySelector('.e-float-text'));
}
};
ReactDOM.render(<App />, document.getElementById('input-container'));

 

Multi-line input with floating label

Add the HTML textarea element with the e-input class to create default multi-line input.

Add the floating label support to the multi-line input by creating the floating label structure as defined in the initial section.

import * as React from "react";
import * as ReactDOM from "react-dom";
export default class App extends React.Component<{}, {}> {
public render() {
    return (
        <div>
            <textarea className="e-input" placeholder="Address"/>
            <div className="e-float-input">
                <textarea required={true}/>
                <span className="e-float-line"/>
                <label className="e-float-text"> Address</label>
            </div>
        </div>
    )
}
};

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

Categories : React

Tags : React Js

Praful Sangani
Praful Sangani
I'm a passionate full-stack developer with expertise in PHP, Laravel, Angular, React Js, Vue, Node, Javascript, JQuery, Codeigniter, and Bootstrap. I enjoy sharing my knowledge by writing tutorials and providing tips to others in the industry. I prioritize consistency and hard work, and I always aim to improve my skills to keep up with the latest advancements. As the owner of Open Code Solution, I'm committed to providing high-quality services to help clients achieve their business goals.


167 Comments

buy tricor medication tricor tablet tricor pill


cialis usa canadian viagra viagra next day delivery usa


order generic ketotifen 1mg ziprasidone 40mg for sale order imipramine for sale


buy minoxytop generic oral mintop best ed pill for diabetics


precose pill buy generic acarbose over the counter buy griseofulvin 250 mg generic


aspirin cheap buy imiquimod imiquimod usa


dipyridamole price pravachol 10mg us purchase pravachol generic


order duphaston 10mg order sitagliptin pills generic empagliflozin 25mg


order monograph without prescription cilostazol 100 mg us cilostazol for sale


order prasugrel 10 mg pill order prasugrel online detrol 1mg generic


buy ferrous sulfate 100mg sale generic ascorbic acid 500mg buy generic sotalol 40mg


order pyridostigmine 60mg online cheap feldene generic purchase maxalt pills


buy cheap generic vasotec order bicalutamide 50mg online buy lactulose online cheap


xalatan where to buy purchase xalatan sale oral rivastigmine 3mg


cheap premarin 600 mg order dostinex viagra fast shipping


omeprazole order oral lopressor lopressor 100mg without prescription


where can i buy telmisartan plaquenil 200mg price purchase molnunat generic


buy cialis 10mg pill tadalafil 20mg viagra pills


cenforce 50mg us buy naprosyn pill cheap chloroquine 250mg


buy provigil 200mg generic promethazine drug deltasone 10mg generic


omnicef 300 mg usa order cefdinir online cheap purchase lansoprazole pills


order absorica generic absorica online buy zithromax online buy


buy generic azithromycin for sale buy azipro 250mg online cheap gabapentin for sale online


order lipitor 10mg order generic albuterol amlodipine cost


money slots play online blackjack for real money order lasix 100mg for sale


order pantoprazole pill order phenazopyridine 200 mg generic buy phenazopyridine 200mg for sale


online casino usa real money jackpot party casino ventolin 4mg cheap


play blackjack online online slot games ivermectin 3mg tabs


amantadine 100mg canada order amantadine 100 mg sale buy generic dapsone 100 mg


free spins no deposit us augmentin online brand synthroid 150mcg


buy clomiphene cheap order azathioprine sale azathioprine price


medrol 4mg without prescription cost adalat 10mg buy aristocort without prescription


vardenafil drug buy zanaflex without a prescription buy tizanidine 2mg generic


generic coversyl generic aceon 4mg buy allegra 120mg pills


buy generic dilantin 100mg order cyclobenzaprine 15mg generic oxybutynin pills


buy baclofen 25mg pill buy elavil cheap oral toradol 10mg


loratadine 10mg generic dapoxetine 60mg uk buy dapoxetine 30mg sale


order ozobax generic order elavil 10mg generic toradol pill


alendronate buy online order furadantin generic buy generic furadantin over the counter


inderal 20mg price buy cheap nurofen where can i buy plavix


glimepiride 4mg without prescription buy generic arcoxia online buy arcoxia sale


buy pamelor paypal generic methotrexate anacin online


order generic coumadin order warfarin 2mg generic order metoclopramide pills


xenical without prescription xenical us diltiazem drug


buy generic astelin buy zovirax 400mg pills buy irbesartan for sale


esomeprazole buy online topamax over the counter buy topamax 100mg without prescription


buy allopurinol 300mg without prescription buy zyloprim 100mg pills oral rosuvastatin 10mg


cheap sumatriptan buy levaquin pills dutasteride order online


order ranitidine 300mg without prescription order ranitidine generic buy celecoxib 100mg for sale


buspar sale generic amiodarone amiodarone 200mg ca


oral domperidone 10mg order carvedilol 25mg without prescription order tetracycline 500mg pills


purchase flomax online cheap order generic zocor simvastatin 10mg price


buy spironolactone pills brand spironolactone 100mg order proscar 5mg pills


cheap term papers best essay writers online edit my paper


buy diflucan pill buy ampicillin without a prescription buy generic ciprofloxacin


sildenafil 50mg oral sildalis us where can i buy yasmin


buy metronidazole 400mg without prescription buy generic metronidazole 400mg buy generic keflex


purchase lamotrigine generic buy lamotrigine 50mg sale order mebendazole without prescription


cheap cleocin 300mg cleocin 150mg pills buy ed pills canada


retin online buy tadalafil 10mg generic avanafil 200mg us


nolvadex price betahistine for sale buy rhinocort online cheap


tadacip 10mg generic diclofenac tablet indocin 75mg tablet


cefuroxime online order robaxin 500mg buy robaxin without prescription


trazodone cheap where to buy desyrel without a prescription buy generic clindamycin


lamisil us purchase lamisil generic best casinos


oral aspirin 75 mg online slots real money usa play roulette


buying an essay problem solving assignment cefixime 200mg canada


pay for essay writing uk casino slots slot machine


amoxicillin 250mg price clarithromycin 250mg canada buy clarithromycin 250mg generic


oral rocaltrol tricor order fenofibrate price


clonidine 0.1mg usa order meclizine 25 mg sale buy spiriva generic


acne medicine prescribed by doctors best doctor prescribed acne medication order oxcarbazepine 300mg online


minocin drug buy minocycline for sale buy requip 1mg online cheap


order uroxatral generic best medication for stomqch cramps what medicine good for heartburn


super strong sleeping pills online weight loss medication clinic weight loss doctor virtual visit


buy letrozole 2.5 mg buy aripiprazole 30mg for sale abilify 30mg for sale


fda approved smoking cessation products drugs used for rheumatoid arthritis ordering pain medication online


medroxyprogesterone 10mg generic purchase praziquantel online buy microzide online


list of medications for herpes does pharmapure sugar blocker work best meds to lower a1c


purchase periactin pills order generic luvox 50mg order ketoconazole 200mg for sale


dangers of fungal medication oral oral medication for fungal rash dr gundry advice


order duloxetine without prescription buy glucotrol 5mg pill buy modafinil 100mg online cheap


best over the counter ulcer medication what classifications antiarrhythmics uti treatment without insurance


promethazine over the counter stromectol 12mg pills buy stromectol pills


birth control pills online order planned parenthood online appointments does hims ed actually work


oral deltasone 40mg accutane pill amoxil 500mg cheap


immediate heartburn relief otc prescribed nausea medication for chemo best medicine to stop farting


buy zithromax 250mg generic prednisolone generic cheap neurontin generic


actigall medication order bupropion 150mg sale cetirizine 5mg oral


strattera 25mg cheap order seroquel 50mg without prescription buy zoloft 100mg online


generic furosemide 40mg purchase albuterol without prescription buy albuterol 2mg inhaler


buy generic escitalopram 20mg buy revia 50 mg generic buy revia 50mg sale


amoxiclav cost amoxiclav online buy clomid uk


combivent 100mcg us order ipratropium 100mcg sale cost zyvox 600 mg


nateglinide price oral nateglinide 120 mg order atacand 16mg sale


levitra 10mg uk tizanidine uk plaquenil brand


carbamazepine pills buy lincocin 500mg online cheap lincomycin 500 mg oral


cenforce 100mg price chloroquine price order glycomet


order lipitor 10mg online zestril 5mg price purchase prinivil pill


purchase duricef pill buy lamivudine without a prescription order epivir for sale


cabergoline usa cabergoline 0.5mg canada order dapoxetine 90mg pills


methylprednisolone 4 mg online aristocort order desloratadine 5mg generic


purchase cytotec xenical tablet diltiazem over the counter


nootropil 800 mg pill clomipramine 25mg for sale order anafranil 50mg online cheap


buy acyclovir 400mg sale zyloprim 100mg oral crestor ca


buy itraconazole paypal tinidazole generic buy tinidazole 300mg without prescription


order zetia sale sumycin price order tetracycline 500mg online cheap


buy zyprexa 10mg without prescription olanzapine 10mg uk diovan 160mg drug


purchase flexeril for sale buy cyclobenzaprine generic buy ketorolac online cheap


buy cheap generic gloperba colchicine pills methotrexate 2.5mg generic


progesterone only pill for acne buy omnacortil cheap best dermatologist treatment for acne


best allergy pill fluorometholone online order walgreen generic allergy pills


what is the strongest sleeping pill phenergan 10mg ca


order deltasone 40mg generic buy prednisone 20mg sale


most effective proton pump inhibitor vomiting after you take medication


salicylic acid versus benzoyl peroxide cefdinir 300 mg oral expensive zit pills


best allergy pill for itching purchase ventolin inhalator generic different types of allergy medicine


natural ways to get rid of acid reflux order duricef 250mg for sale


buy isotretinoin 40mg sale order accutane 20mg generic generic accutane


order sleeping tablets online uk order melatonin 3mg pills


purchase amoxicillin without prescription cheap amoxicillin 250mg amoxicillin sale


order zithromax generic buy zithromax 250mg without prescription buy azithromycin 250mg for sale


order gabapentin 100mg online cheap buy neurontin generic


azithromycin 500mg us azipro 500mg pills azithromycin 250mg for sale


furosemide pill furosemide 40mg tablet


buy omnacortil tablets order omnacortil 20mg without prescription omnacortil 20mg usa


generic amoxicillin 250mg order amoxil 500mg sale amoxicillin 500mg tablet


doxycycline 100mg uk oral doxycycline 200mg


albuterol without prescription order albuterol buy albuterol inhalator for sale


amoxiclav price buy augmentin generic


order levothroid online cheap levoxyl for sale synthroid 75mcg cheap


vardenafil 20mg uk buy levitra online


buy clomiphene online clomiphene us buy serophene without prescription


order tizanidine 2mg without prescription order tizanidine 2mg brand tizanidine 2mg


rybelsus 14 mg oral oral semaglutide 14 mg rybelsus 14 mg oral


prednisone brand deltasone 10mg drug buy generic prednisone online


buy semaglutide 14 mg pills buy rybelsus tablets semaglutide price


oral ventolin 2mg buy generic albuterol albuterol 2mg tablet


amoxicillin 1000mg drug amoxicillin uk order amoxil 500mg without prescription


order augmentin amoxiclav generic amoxiclav ca


order generic azithromycin 250mg azithromycin for sale online buy azithromycin 500mg online cheap


levothroid generic levothyroxine price levoxyl uk


cost omnacortil 10mg purchase prednisolone prednisolone 10mg without prescription


casino online real money casino games online world tavern poker online


order generic vardenafil 20mg buy vardenafil 10mg pills order vardenafil 20mg pill


order lyrica 150mg online cheap lyrica 150mg without prescription cheap lyrica 75mg


cost hydroxychloroquine buy plaquenil 200mg without prescription buy generic hydroxychloroquine over the counter


order triamcinolone without prescription brand aristocort buy triamcinolone 4mg online


buy tadalafil 40mg pill cialis 10mg pill order generic cialis 10mg


buy desloratadine generic order generic desloratadine 5mg desloratadine ca


cenforce 50mg price how to get cenforce without a prescription cenforce generic


buy generic loratadine over the counter buy claritin no prescription order claritin


buy aralen cheap chloroquine 250mg price chloroquine online


order priligy 30mg online dapoxetine 60mg us brand cytotec 200mcg


buy glycomet paypal order metformin 500mg generic buy glycomet without prescription


buy generic orlistat 60mg order diltiazem generic diltiazem oral


lipitor 20mg pill buy atorvastatin paypal buy lipitor 10mg for sale


zovirax order online buy allopurinol 300mg pills buy zyloprim without a prescription


order norvasc online cheap norvasc 5mg norvasc 5mg drug


where can i buy rosuvastatin purchase zetia pill order zetia generic


lisinopril 5mg tablet lisinopril 10mg cheap zestril 5mg oral


buy motilium domperidone cost order tetracycline 250mg generic


prilosec over the counter order prilosec 20mg for sale cost prilosec 10mg


cyclobenzaprine 15mg drug order ozobax baclofen oral


oral metoprolol order lopressor 100mg for sale buy lopressor pills for sale


toradol ca order colcrys 0.5mg colcrys online


atenolol brand atenolol 100mg oral purchase tenormin


Leave a comment

We'll never share your email with anyone else. Required fields are marked *

Related Articles