Search results

Customize the TextBox Background-color and Text-color in React TextBox component

26 Nov 2021 / 1 minute to read

You can customize the textbox styles such as background-color, text-color and border-color by overriding its default styles.

To change the styles of the floating label, you must override the style to the input element.

Source
Preview
index.tsx
index.css
Copied to clipboard
import * as React from "react";
import * as ReactDOM from "react-dom";

export default class App extends React.Component<{}, {}> {
    constructor(props: any) {
        super(props);
    }
    public render() {
        return (
            <div className="wrap">
            <label> Normal Input </label>
            <div className="e-input-group">
                <input className="e-input" onFocus= {this.floatFocus} onBlur= {this.floatBlur} type="text" placeholder="First Name"/>
            </div>
            <label> Floating Input </label>
            <div className="e-float-input">
                <input type="text" required={true} />
                <span className="e-float-line"/>
                <label className="e-float-text">Last Name</label>
            </div>
        </div>
        );
    }
    private floatFocus(args: React.FocusEvent): void {
        ((args.target as HTMLElement).parentElement as HTMLElement).classList.add('e-input-focus');
    }
    private floatBlur(args: React.FocusEvent): void {
        ((args.target as HTMLElement).parentElement as HTMLElement).classList.remove('e-input-focus');
    }
}
ReactDOM.render(<App />, document.getElementById('input-container'));
Copied to clipboard
/* To change the background-color and text-color for textbox */ 
.e-input-group,
.e-float-input,
.e-float-input.e-input-group { 
  background : lightgray;
  color: green;
}

/* To change the border-color of the textbox */ 
.e-input-group:not(.e-success):not(.e-warning):not(.e-error):not(.e-float-icon-left),
.e-input-group:hover:not(.e-success):not(.e-warning):not(.e-error):not(.e-float-icon-left) {
  border-color: #0800ff;
}

/* To change the border-color of the floating-label textbox */ 
.e-float-input input,
.e-float-input:hover:not(.e-input-group):not(.e-success):not(.e-warning):not(.e-error):not(.e-disabled) input:not([disabled]) {
    border-color: #0800ff;
}

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

.wrap {
box-sizing: border-box;
margin: 0 auto;
padding: 20px 10px;
width: 260px;
}

.wrap label {
font-weight:bold;
}

.wrap .e-float-input {
 margin:30px 0;
}

.wrap .e-input-group {
 margin:25px 0;
}