|
| 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