Skip to content

Commit d758c41

Browse files
authored
Create getTextTotalLine.js
1 parent bb878d2 commit d758c41

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const getTextTotalLine = (el) => {
2+
let divHeight = 1;
3+
if (el.tagName === 'TEXTAREA') {
4+
divHeight = el.scrollHeight;
5+
} else {
6+
divHeight = el.offsetHeight;
7+
}
8+
let lineHeight = window
9+
.getComputedStyle(el, null)
10+
.getPropertyValue('line-height');
11+
lineHeight = parseFloat(lineHeight.split('px')[0]);
12+
let totalLine = Math.ceil(divHeight / lineHeight);
13+
return totalLine;
14+
}
15+
16+
const onChange = () => {
17+
const totalLine = getTextTotalLine(anchorEl.current);
18+
}
19+
20+
return (
21+
<div className={elementClass}>
22+
<textarea onChange={onChange} value={value} id={`${classPrefix}-textarea${instanceId}`} placeholder={placeholder} ref={anchorEl} />
23+
</div>
24+
);

0 commit comments

Comments
 (0)