feat(input): implement maxLength in js rather then using the maxlength prop of the input field

This is explained in #685. Fixes #685 therefore.
old
Simon Selg 2016-08-04 03:45:38 +02:00
parent 8559c1818c
commit a8dbad121f
1 changed files with 10 additions and 3 deletions

View File

@ -83,7 +83,15 @@ const factory = (FontIcon) => {
}
handleChange = (event) => {
if (this.props.onChange) this.props.onChange(event.target.value, event);
const { onChange, multiline, maxLength } = this.props;
const valueFromEvent = event.target.value;
// trim value to maxLength if that exists (only on multiline inputs)
const haveToTrim = (multiline && maxLength && event.target.value.length > maxLength);
const value = haveToTrim ? valueFromEvent.substr(0, maxLength) : valueFromEvent;
// propagate to to store and therefore to the input
if (onChange) onChange(value, event);
};
handleAutoresize = () => {
@ -136,8 +144,7 @@ const factory = (FontIcon) => {
disabled,
required,
type,
value,
maxLength
value
});
return (