We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bb878d2 commit d758c41Copy full SHA for d758c41
1 file changed
js-coding-technique/getTextTotalLine.js
@@ -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