Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d758c41

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

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎js-coding-technique/getTextTotalLine.js

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)

AltStyle によって変換されたページ (->オリジナル) /