Skip to content

Commit

Permalink
Merge branch 'master' into react16
Browse files Browse the repository at this point in the history
  • Loading branch information
taoqili committed Nov 20, 2018
2 parents 92266eb + b25ebdd commit bf5435f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/TextareaFormField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,28 @@ class TextAreaFormField extends FormField {
}
});
if (element) {
const Count = React.cloneElement(element, {
length: me.state.value ? me.state.value.length : 0,
const mixed = element.props.mixed;
const value = me.state.value;
const len = value ? TextAreaFormField.getStringLen(value, mixed) : 0;
return React.cloneElement(element, {
length: len,
key: 'count',
});

return Count;
}
return null;
}

static getStringLen(string, mixed) {
let len = string.length;
if (!mixed) {
return len;
}
let reLen = 0;
for (let i = 0; i < len; i++) {
reLen += (string.charCodeAt(i) <= 128 ? 1 : 2)
}
return Math.ceil(reLen / 2);
}

renderField() {
const me = this;
Expand Down Expand Up @@ -176,6 +188,7 @@ class TextAreaFormField extends FormField {
<span
style={{
whiteSpace: 'pre-wrap',
overflowWrap: 'break-word',
}}
className="view-mode"
>{me.state.value}</span>
Expand Down

0 comments on commit bf5435f

Please sign in to comment.