Skip to content

Commit

Permalink
input performance improved
Browse files Browse the repository at this point in the history
  • Loading branch information
abdurrahmanekr committed Jul 20, 2020
1 parent f95508b commit 8a4c7f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-chat-elements",
"version": "10.9.2",
"version": "10.9.3",
"description": "Reactjs chat components",
"author": "Avare Kodcu <[email protected]>",
"main": "dist/main.js",
Expand Down
36 changes: 19 additions & 17 deletions src/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,33 @@ import './Input.css';
const classNames = require('classnames');

export class Input extends Component {
constructor(props) {
super(props);

this.state = {
value: this.props.defaultValue,
};
}

onChange(e) {
if (this.props.maxlength && (e.target.value || '').length > this.props.maxlength) {
if (this.props.onMaxLengthExceed instanceof Function)
this.props.onMaxLengthExceed();

this.input.value = (e.target.value || '').substring(0, this.props.maxlength);
return;
}

this.setState({
value: e.target.value
});
if (this.props.onChange instanceof Function)
this.props.onChange(e);

if (this.props.multiline === true) {
if (this.props.autoHeight === true) {
e.target.style.height = this.props.minHeight + 'px';
if (e.target.style.height !== this.props.minHeight + 'px') {
e.target.style.height = this.props.minHeight + 'px';
}

let height;
if (e.target.scrollHeight <= this.props.maxHeight)
e.target.style.height = e.target.scrollHeight + 'px';
height = e.target.scrollHeight + 'px';
else
e.target.style.height = this.props.maxHeight + 'px';
height = this.props.maxHeight + 'px';

if (e.target.style.height !== height) {
e.target.style.height = height;
}
}
}
}
Expand All @@ -42,7 +40,11 @@ export class Input extends Component {
FAKE_EVENT: true,
target: this.input,
};
this.input.value = '';

if (this.input.value) {
this.input.value = '';
}

this.onChange(event);
}

Expand Down Expand Up @@ -71,7 +73,7 @@ export class Input extends Component {
type={this.props.type}
className={classNames('rce-input')}
placeholder={this.props.placeholder}
value={this.state.value}
defaultValue={this.props.defaultValue}
style={this.props.inputStyle}
onChange={this.onChange.bind(this)}
onCopy={this.props.onCopy}
Expand All @@ -95,7 +97,7 @@ export class Input extends Component {
type={this.props.type}
className={classNames('rce-input', 'rce-input-textarea')}
placeholder={this.props.placeholder}
value={this.state.value}
defaultValue={this.props.defaultValue}
style={this.props.inputStyle}
onChange={this.onChange.bind(this)}
onCopy={this.props.onCopy}
Expand Down

0 comments on commit 8a4c7f3

Please sign in to comment.